Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created October 17, 2012 15:54
Show Gist options
  • Save fixlr/3906333 to your computer and use it in GitHub Desktop.
Save fixlr/3906333 to your computer and use it in GitHub Desktop.
#!/user/bin/env ruby
require 'benchmark'
ary = []
10000.times {
ary << rand(10000)
}
Benchmark.bm do |x|
x.report("sort") { ary.sort{ |a,b| b <=> a } }
x.report("sort reverse") { ary.sort.reverse }
end
# user system total real
# sort 0.010000 0.000000 0.010000 ( 0.012878)
# sort reverse 0.000000 0.000000 0.000000 ( 0.001522)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment