Skip to content

Instantly share code, notes, and snippets.

@piotrze
Created February 14, 2018 14:11
Show Gist options
  • Save piotrze/008dbf436299a592d0a720a113daef80 to your computer and use it in GitHub Desktop.
Save piotrze/008dbf436299a592d0a720a113daef80 to your computer and use it in GitHub Desktop.
Benchmark case over public_send
require 'benchmark'
class A
def call_case(var = 'a')
case var
when 'a'
a
end
end
def call_send_public(var = 'a')
public_send(var)
end
def a
end
end
o = A.new
Benchmark.bm(10) do |x|
x.report('case') { 100000.times{ o.call_case }}
x.report('public_send') { 100000.times{ o.call_send_public }}
end
# user system total real
# case 0.020000 0.000000 0.020000 ( 0.017094)
# public_send 0.020000 0.000000 0.020000 ( 0.024422)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment