Skip to content

Instantly share code, notes, and snippets.

@thisivan
Created June 23, 2009 17:35
Show Gist options
  • Save thisivan/134698 to your computer and use it in GitHub Desktop.
Save thisivan/134698 to your computer and use it in GitHub Desktop.
Sample benchmarks on Ruby
require 'benchmark'
puts Benchmark.measure { "a"*1_000_000 }
0.060000 0.000000 0.060000 ( 0.067556)
=> nil
n = 50000
Benchmark.bm do |x|
x.report { for i in 1..n; a = "1"; end }
x.report { n.times do ; a = "1"; end }
x.report { 1.upto(n) do ; a = "1"; end }
end
user system total real
0.080000 0.010000 0.090000 ( 0.099025)
0.040000 0.000000 0.040000 ( 0.038261)
0.030000 0.010000 0.040000 ( 0.036234)
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment