Skip to content

Instantly share code, notes, and snippets.

@dydx
Created January 24, 2010 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dydx/285390 to your computer and use it in GitHub Desktop.
Save dydx/285390 to your computer and use it in GitHub Desktop.
# benchmarking.rb - Josh Sandlin - 1:58PM - 1/24/2010
# benchmarking from the unofficial ruby usage guide
require 'benchmark'
include Benchmark
n = 1000000
bm( 12 ) do |test|
test.report( "normal:" ) do
n.times do |x|
y = x + 1
end
end
test.report( "predefine:" ) do
x = y = 0
n.times do |x|
y = x + 1
end
end
end
# ruby benchmarking.rb
# user system total real
# normal: 0.546000 0.000000 0.546000 ( 0.556000)
# predefine: 0.468000 0.000000 0.468000 ( 0.464000)
# jruby benchmarking.rb
# user system total real
# normal: 0.508000 0.000000 0.508000 ( 0.335000)
# predefine: 0.282000 0.000000 0.282000 ( 0.282000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment