Skip to content

Instantly share code, notes, and snippets.

@qrush
Created April 22, 2011 00:28
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 qrush/935775 to your computer and use it in GitHub Desktop.
Save qrush/935775 to your computer and use it in GitHub Desktop.
super scientific benchmarking of #member? vs #include?
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)
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