Skip to content

Commit

Permalink
bench Integer #even/#odd, #times and #upto/#downto
Browse files Browse the repository at this point in the history
  • Loading branch information
burningTyger committed Mar 14, 2011
1 parent bfb2acc commit e52290a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
56 changes: 56 additions & 0 deletions benchmark/core/integer/bench_even_odd.rb
@@ -0,0 +1,56 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|

#Integer#even
x.report "Integer#even? true" do |times|
i = 0
while i < times
2.even?
i += 1
end
end

x.report "Integer#even? false" do |times|
i = 0
while i < times
1.even?
i += 1
end
end

x.report "Integer#even? alternating" do |times|
i = 0
while i < times
i.even?
i += 1
end
end

#Integer#odd
x.report "Integer#odd? true" do |times|
i = 0
while i < times
1.even?
i += 1
end
end

x.report "Integer#odd? false" do |times|
i = 0
while i < times
2.even?
i += 1
end
end

x.report "Integer#odd? alternating" do |times|
i = 0
while i < times
i.even?
i += 1
end
end

end
14 changes: 14 additions & 0 deletions benchmark/core/integer/bench_times.rb
@@ -0,0 +1,14 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|

x.report "Integer#times" do |times|
i = 0
while i < times
1000.times{ |x| }
i += 1
end
end

end
22 changes: 22 additions & 0 deletions benchmark/core/integer/bench_up_down.rb
@@ -0,0 +1,22 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|

x.report "Integer#downto" do |times|
i = 0
while i < times
10000.downto(1)
i += 1
end
end

x.report "Integer#upto" do |times|
i = 0
while i < times
1.upto(10000)
i += 1
end
end

end

0 comments on commit e52290a

Please sign in to comment.