The rdoc for the Benchmark module contains the following snippet:
require 'benchmark'
puts Benchmark.measure { "a"*1_000_000 }
# On my machine (FreeBSD 3.2 on P5, 100MHz) this generates:
1.166667 0.050000 1.216667 ( 0.571355)I was curious as to how well this trivial benchmark performs on a modern system and Ruby.
I'm running these tests on a 2.66ghz Core i7 2010 MBP.
>> puts Benchmark.measure { "a"*1_000_000 }
0.010000 0.000000 0.010000 ( 0.005487)
>> puts Benchmark.measure { "a"*1_000_000_000 }
4.220000 0.440000 4.660000 ( 4.669077)irb(main):002:0> puts Benchmark.measure { "a"*1_000_000 }
0.000000 0.000000 0.000000 ( 0.004467)
irb(main):003:0> puts Benchmark.measure { "a"*1_000_000_000 }
3.910000 0.430000 4.340000 ( 4.339834)ruby-1.9.2-p290 :002 > puts Benchmark.measure { "a"*1_000_000 }
0.000000 0.000000 0.000000 ( 0.001150)
ruby-1.9.2-p290 :003 > puts Benchmark.measure { "a"*1_000_000_000 }
0.280000 0.420000 0.700000 ( 0.790797)ruby-1.9.3-p0 :002 > puts Benchmark.measure { "a"*1_000_000 }
0.000000 0.000000 0.000000 ( 0.000776)
ruby-1.9.3-p0 :003 > puts Benchmark.measure { "a"*1_000_000_000 }
0.280000 0.410000 0.690000 ( 0.776747)