From 7b4732e9b72a8143b73cd124c51b478495635b24 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Sun, 4 Dec 2011 13:42:40 +0100 Subject: [PATCH] Add benchmark for Bignum#to_s --- benchmark/core/bignum/bench_to_s.rb | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 benchmark/core/bignum/bench_to_s.rb diff --git a/benchmark/core/bignum/bench_to_s.rb b/benchmark/core/bignum/bench_to_s.rb new file mode 100644 index 0000000000..ac42253e68 --- /dev/null +++ b/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