File: odd.rb

package info (click to toggle)
ruby-distribution 0.7.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 624 kB
  • ctags: 379
  • sloc: ruby: 4,283; makefile: 7
file content (22 lines) | stat: -rw-r--r-- 292 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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