Skip to content
Browse files

Add benchmark for Bignum#to_s

  • Loading branch information...
1 parent a49605a commit 7b4732e9b72a8143b73cd124c51b478495635b24 @dbussink dbussink committed Dec 4, 2011
Showing with 44 additions and 0 deletions.
  1. +44 −0 benchmark/core/bignum/bench_to_s.rb
View
44 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.
Something went wrong with that request. Please try again.