Skip to content

Instantly share code, notes, and snippets.

@chief
Created February 11, 2014 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chief/8944843 to your computer and use it in GitHub Desktop.
Save chief/8944843 to your computer and use it in GitHub Desktop.
Ruby min Vs sort Vs sort!
#! /usr/bin/env ruby
require "benchmark"
Benchmark.bmbm(7) do |x|
iterations = 10_000
a = 4000.times.map { |i| rand(i * 100).to_i }
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