Created
March 15, 2010 14:31
-
-
Save rdp/332879 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' | |
| def yields | |
| yield | |
| end | |
| def named_block &block | |
| block.call | |
| end | |
| class A | |
| def go | |
| end | |
| def get_proc | |
| @proc ||= proc {} | |
| end | |
| end | |
| 3.times { | |
| Benchmark.bm do |x| | |
| n = 100000 | |
| x.report("straight yield ") { n.times { yields {}}} | |
| x.report("named block ") { n.times { named_block {}}} | |
| a = A.new | |
| x.report("cached proc ") { n.times { named_block(&a.get_proc) }} | |
| end | |
| } |
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
| jruby --server | |
| straight yield 0.047000 0.000000 0.047000 ( 0.047000) * slower | |
| named block 0.094000 0.000000 0.094000 ( 0.094000) | |
| cached proc 0.093000 0.000000 0.093000 ( 0.093000) * slower | |
| jruby --server --fast | |
| straight yield 0.031000 0.000000 0.031000 ( 0.031000) | |
| named block 0.094000 0.000000 0.094000 ( 0.094000) | |
| cached proc 0.078000 0.000000 0.078000 ( 0.078000) | |
| 1.9.1 | |
| straight yield 0.031000 0.000000 0.031000 ( 0.031250) | |
| named block 0.672000 0.015000 0.687000 ( 0.687500) | |
| cached proc 0.078000 0.000000 0.078000 ( 0.078125) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment