Skip to content

Instantly share code, notes, and snippets.

@jarib
Created April 26, 2010 22:01
Show Gist options
  • Save jarib/379998 to your computer and use it in GitHub Desktop.
Save jarib/379998 to your computer and use it in GitHub Desktop.
def foo(*args)
args
end
require "benchmark"
TESTS = 1_000_000
Benchmark.bmbm do |results|
results.report("hash:") { TESTS.times { foo(:foo => 'bar') } }
results.report("2 args:") { TESTS.times { foo(:foo, 'bar') } }
end
#
#
#
# output:
#
#
#
# Rehearsal -------------------------------------------
# hash: 2.470000 0.060000 2.530000 ( 2.559726)
# 2 args: 1.190000 0.010000 1.200000 ( 1.225796)
# ---------------------------------- total: 3.730000sec
#
# user system total real
# hash: 2.500000 0.060000 2.560000 ( 2.628864)
# 2 args: 1.200000 0.010000 1.210000 ( 1.205671)
# copy output
# Program exited with code #0 after 7.68 seconds.
#
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment