Skip to content

Commit

Permalink
Add benchmark for Bignum#to_s
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Dec 4, 2011
1 parent a49605a commit 7b4732e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmark/core/bignum/bench_to_s.rb
@@ -0,0 +1,44 @@
require 'benchmark'
require 'benchmark/ips'
require 'benchmark/helpers'

Benchmark.ips do |x|

small_bignum = Benchmark::Helpers.fixnum_max + 1
medium_bignum = Benchmark::Helpers.fixnum_max ** 10
large_bignum = Benchmark::Helpers.fixnum_max ** 100
huge_bignum = Benchmark::Helpers.fixnum_max ** 1000

x.report "small Bignum#to_s" do |times|
i = 0
while i < times
small_bignum.to_s
i += 1
end
end

x.report "medium Bignum#to_s" do |times|
i = 0
while i < times
medium_bignum.to_s
i += 1
end
end

x.report "large Bignum#to_s" do |times|
i = 0
while i < times
large_bignum.to_s
i += 1
end
end

x.report "huge Bignum#to_s" do |times|
i = 0
while i < times
huge_bignum.to_s
i += 1
end
end

end

0 comments on commit 7b4732e

Please sign in to comment.