Created
February 14, 2018 14:11
-
-
Save piotrze/008dbf436299a592d0a720a113daef80 to your computer and use it in GitHub Desktop.
Benchmark case over public_send
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 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