Created
June 23, 2009 17:35
-
-
Save thisivan/134698 to your computer and use it in GitHub Desktop.
Sample benchmarks on Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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