-
-
Save ELLIOTTCABLE/2534 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
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 | |
__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