Skip to content

Instantly share code, notes, and snippets.

@rShetty
Last active August 29, 2015 14:16
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 rShetty/d9a15645697aa2632037 to your computer and use it in GitHub Desktop.
Save rShetty/d9a15645697aa2632037 to your computer and use it in GitHub Desktop.
Benchmark IPS
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.time = 5
x.warmup = 2
times = 10000
x.report("report_1") do
times.times do
(('a'..'z').to_a + ('0'..'9').to_a).repeated_permutation(2).to_a.sample(1).join
end
end
x.report("report_2") do
times.times do
(('a'..'z').to_a + ('0'..'9').to_a).sample(2).join
end
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment