&method(...) section misleading
amencarini opened this issue · 1 comments
amencarini commented
I found the &method(...) section a bit misleading, as I never found myself writing code that way, but alarmed me as I use Symbol#to_proc
a lot. So I ran a different benchmark:
require "benchmark/ips"
def fast
[1, 2, 3].map { |n| n.to_s }
end
def slow
[1, 2, 3].map(&:to_s)
end
Benchmark.ips do |x|
x.report("normal") { fast }
x.report("&method") { slow }
x.compare!
end
Calculating -------------------------------------
normal 59.170k i/100ms
&method 57.531k i/100ms
-------------------------------------------------
normal 1.118M (±11.5%) i/s - 5.562M
&method 1.067M (±12.4%) i/s - 5.293M
Comparison:
normal: 1118235.4 i/s
&method: 1067078.5 i/s - 1.05x slower
Although I later found something targeting specifically to_proc
I think it's worth making it clear that we're not talking about Symbol#to_proc
syntax here. Thoughts?
JuanitoFatas commented
Hi! &method
& Symbol#to_proc
are different. Please see the explanations here: cf64ab7#commitcomment-12068179. Hope this helps.