Created
March 15, 2010 16:32
-
-
Save rdp/333015 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' | |
| class A | |
| def initialize | |
| @yo_block_1 = proc {|n| n * 2} | |
| end | |
| def go &block | |
| yield (3) | |
| end | |
| def go_non_named | |
| yield(3) | |
| end | |
| def yo | |
| @yo_block_1 ||= proc {|n| n * 2} | |
| go &@yo_block_1 | |
| end | |
| def yo_slow | |
| go {|n| n * 2} | |
| end | |
| def yo_yield | |
| go_non_named { |n| n * 2} | |
| end | |
| end | |
| b = A.new | |
| n = 1 | |
| n = 3 if RUBY_PLATFORM =~ /java/ | |
| n.times { | |
| puts Benchmark.realtime { 1000000.times { b.yo_yield }} | |
| puts Benchmark.realtime { 1000000.times { b.yo }} | |
| puts Benchmark.realtime { 1000000.times { b.yo_slow }} | |
| } |
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
| E:\dev\digitalarchive_trunk.trunk>e:\dev\ruby\downloads\jruby\bin\jruby.EXE --server --fast speed_test.rb | |
| ... | |
| 0.421000003814697 # yield | |
| 0.421999931335449 # cached | |
| 0.672000169754028 # named | |
| 1.9.1: | |
| 0.40625 # yield | |
| 0.609375 # cached | |
| 5.546875 # named |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment