Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created March 31, 2009 22:59
Show Gist options
  • Select an option

  • Save methodmissing/88463 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/88463 to your computer and use it in GitHub Desktop.
#!/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
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