-
-
Save maasha/1c108f9d45c1de917b1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'inline' | |
require 'benchmark' | |
hash = {foo: "bar"} | |
n = 10_000_000 | |
Benchmark.bm() do |x| | |
x.report("hash[]") { n.times { hash[:foo] } } | |
x.report("hash.has_key?") { n.times { hash.has_key? :foo } } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maasha@mel:~$ ./benchmark.rb | |
user system total real | |
hash[] 1.100000 0.000000 1.100000 ( 1.111618) | |
hash.has_key? 1.360000 0.000000 1.360000 ( 1.364842) | |
maasha@mel:~$ rbx benchmark.rb | |
user system total real | |
hash[] 2.341919 0.019072 2.360991 ( 2.272809) | |
hash.has_key? 1.915534 0.002146 1.917680 ( 1.860527) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment