Created
February 11, 2014 21:45
-
-
Save chief/8944843 to your computer and use it in GitHub Desktop.
Ruby min Vs sort Vs sort!
This file contains hidden or 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
#! /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