Created
October 3, 2012 00:25
-
-
Save tancnle/3824191 to your computer and use it in GitHub Desktop.
Benchmark shuffle and sample
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" | |
foo = (1..100).to_a | |
n = 1000000 | |
Benchmark.bm do |x| | |
x.report("shuffle") { n.times do; bar = foo.shuffle.first ; end} | |
x.report("sample") { n.times do; bar = foo.sample ; end} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment