Created
April 22, 2011 00:28
-
-
Save qrush/935775 to your computer and use it in GitHub Desktop.
super scientific benchmarking of #member? vs #include?
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
Rehearsal ----------------------------------------- | |
set 0.680000 0.000000 0.680000 ( 0.689172) | |
array 0.750000 0.000000 0.750000 ( 0.749196) | |
-------------------------------- total: 1.430000sec | |
user system total real | |
set 0.700000 0.010000 0.710000 ( 0.693745) | |
array 0.750000 0.000000 0.750000 ( 0.751151) |
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
require 'benchmark' | |
require 'set' | |
Benchmark.bmbm do |bm| | |
set = Set.new(["message", "pmessage"]) | |
array = ["message", "pmessage"] | |
bm.report("set") do | |
1_000_000.times do | |
set.member?("pmessage") | |
end | |
end | |
bm.report("array") do | |
1_000_000.times do | |
array.include?("pmessage") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment