Skip to content

Instantly share code, notes, and snippets.

@jjb
Created September 26, 2023 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjb/2d5ded544be8a2d09c3da192fd7c41cf to your computer and use it in GitHub Desktop.
Save jjb/2d5ded544be8a2d09c3da192fd7c41cf to your computer and use it in GitHub Desktop.
benchmark ruby rand vs rand(100)
require 'benchmark/ips'
require "benchmark/memory"
Benchmark.ips do |x|
x.report("rand") do
rand
end
x.report("rand(100)") do
rand(100)
end
end
Benchmark.memory do |x|
x.report("rand") do
rand
end
x.report("rand(100)") do
rand(100)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment