Sha256: 46b74641f763f63abbb269a9f7ef21e553bb14992f93f519056358ca80c3e51b

Contents?: true

Size: 292 Bytes

Versions: 8

Compression:

Stored size: 292 Bytes

Contents

require 'bench_press'

extend BenchPress

name 'n&1==1 vs n%2==1 to detect odd numbers'
author 'Claudio Bustos'
date '2011-01-28'
summary "
Which is faster, n%1==1 or n%2==1
"

reps 10_000 #number of repetitions
n=100000
measure "Using &" do
  n%1==1
end

measure "Using %" do
  n%2==1
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
distribution-0.7.3 benchmark/odd.rb
distribution-0.7.2 benchmark/odd.rb
distribution-0.7.1 benchmark/odd.rb
distribution-0.7.0 benchmark/odd.rb
distribution-0.6.0 benchmark/odd.rb
distribution-0.5.0 benchmark/odd.rb
distribution-0.4.0 benchmark/odd.rb
distribution-0.3.0 benchmark/odd.rb