Skip to content

Instantly share code, notes, and snippets.

@workmad3
Forked from chief/gist:8944843
Last active August 29, 2015 13:56
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 workmad3/8945034 to your computer and use it in GitHub Desktop.
Save workmad3/8945034 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "benchmark"
Benchmark.bmbm(7) do |x|
iterations = 10_000
a = 4000.times.map { |i| rand(i * 100).to_i }
a.sort!
x.report("min") do
iterations.times do |i|
a.min
end
end
x.report("sort!.first") do
iterations.times do |i|
a.sort!.first
end
end
x.report("sort.first") do
iterations.times do |i|
a.sort.first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment