Skip to content

Instantly share code, notes, and snippets.

@bryanp
Last active April 14, 2016 18:21
Show Gist options
  • Save bryanp/6f54a53a0eff4d2ed8dbfcc10833b093 to your computer and use it in GitHub Desktop.
Save bryanp/6f54a53a0eff4d2ed8dbfcc10833b093 to your computer and use it in GitHub Desktop.
Ruby Benchmark Quiz
# Comment with what benchmark you think would be faster, and why.
require "benchmark"
data = {
'foo' => 'bar'
}
count = 100_000_000
time = Benchmark.measure do
count.times do
data['foo']
end
end
puts time
key = 'foo'
time = Benchmark.measure do
count.times do
data[key]
end
end
puts time
@iamvery
Copy link

iamvery commented Apr 14, 2016

● master ~/Desktop » ruby quiz.rb
  8.350000   0.010000   8.360000 (  8.365999)
 11.740000   0.050000  11.790000 ( 11.959589)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment