Skip to content

Instantly share code, notes, and snippets.

@kalmanh
Created July 19, 2013 05:59
Show Gist options
  • Save kalmanh/6036968 to your computer and use it in GitHub Desktop.
Save kalmanh/6036968 to your computer and use it in GitHub Desktop.
Shows how much slower Random.new.rand() is vs. Kernel's rand()
require 'benchmark'
NUM_TIMES = 10000
Benchmark.bmbm do |x|
x.report("Random.new") do
NUM_TIMES.times do
Random.new.rand(2.0...4.0)
end
end
x.report("rand") do
NUM_TIMES.times do
rand(2.0...4.0)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment