Created
March 31, 2009 22:59
-
-
Save methodmissing/88463 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
| #!/usr/bin/env ruby | |
| require "rubygems" | |
| require "rbench" | |
| class Object | |
| CALLSITE_SAMPLE = 1..3 | |
| def callsite_with_constant_append( *signature ) | |
| ( caller[CALLSITE_SAMPLE] << signature ).hash | |
| end | |
| def callsite_without_constant_append( *signature ) | |
| ( caller[1..3] << signature ).hash | |
| end | |
| def callsite_with_constant_concat( *signature ) | |
| ( caller[CALLSITE_SAMPLE].concat( signature ) ).hash | |
| end | |
| def callsite_without_constant_concat( *signature ) | |
| ( caller[1..3].concat( signature ) ).hash | |
| end | |
| end | |
| RBench.run(10_000) do | |
| report "Object#callsite_with_constant_append" do | |
| callsite_with_constant_append | |
| callsite_with_constant_append( :one, 'two' ) | |
| end | |
| report "Object#callsite_without_constant_append" do | |
| callsite_without_constant_append | |
| callsite_without_constant_append( :one, 'two' ) | |
| end | |
| report "Object#callsite_with_constant_concat" do | |
| callsite_with_constant_concat | |
| callsite_with_constant_concat( :one, 'two' ) | |
| end | |
| report "Object#callsite_without_constant_concat" do | |
| callsite_without_constant_concat | |
| callsite_without_constant_concat( :one, 'two' ) | |
| end | |
| 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
| 213-138-231-158:extlib lourens$ ruby benchmarks/callsite.rb | |
| Results | | |
| --------------------------------------------------------- | |
| Object#callsite_with_constant_append 0.358 | | |
| Object#callsite_without_constant_append 0.349 | | |
| Object#callsite_with_constant_concat 0.312 | | |
| Object#callsite_without_constant_concat 0.336 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment