Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2008 21:26
Show Gist options
  • Save anonymous/2533 to your computer and use it in GitHub Desktop.
Save anonymous/2533 to your computer and use it in GitHub Desktop.
require 'benchmark'
TIMES = 10_000_000
:foo # Anal-retentivity
def thrice_yield
3.times { yield }
end
def thrice_block &block
3.times &block
end
def thrice_proc_dot_new
3.times &Proc.new # Yes, you can do that.
end
print " " # Prettiness :3
Benchmark.bm do |bm|
bm.report " yield" do
TIMES.times do
thrice_yield { :foo }
end
end
bm.report " block" do
TIMES.times do
thrice_block { :foo }
end
end
bm.report "Proc.new" do
TIMES.times do
thrice_proc_dot_new { :foo }
end
end
end
user system total real
yield 16.860000 0.110000 16.970000 ( 18.369037)
block 40.110000 0.290000 40.400000 ( 43.453339)
Proc.new 37.430000 0.250000 37.680000 ( 40.708240)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment