Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created December 20, 2011 02:42
Show Gist options
  • Save mipearson/1499988 to your computer and use it in GitHub Desktop.
Save mipearson/1499988 to your computer and use it in GitHub Desktop.

benchmark.rb Demonstration On a Modern System

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.

ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

>> 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)

ree-1.8.7-2011.03

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

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

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment