Skip to content

Instantly share code, notes, and snippets.

@tancnle
Created October 3, 2012 00:25
Show Gist options
  • Save tancnle/3824191 to your computer and use it in GitHub Desktop.
Save tancnle/3824191 to your computer and use it in GitHub Desktop.
Benchmark shuffle and sample
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