[ruby-core:126405] [Ruby Misc#10983] Why blocks make Ruby methods 439% slower ?
Issue #10983 has been updated by Earlopain (Earlopain _). Status changed from Open to Closed Today the difference is only ~1.25x slower, not nearly as bad as it used to be. YJIT also improves both versions by at least 2x, altough it is able to optimize yield more than the explicit call. ---------------------------------------- Misc #10983: Why blocks make Ruby methods 439% slower ? https://bugs.ruby-lang.org/issues/10983#change-118543 * Author: Sega100500 (Сергей Е) * Status: Closed ---------------------------------------- https://www.omniref.com/ruby/2.2.0/symbols/Proc/yield#annotation=4087638&line=711&hn=1 ~~~ruby require 'benchmark/ips' def block_call(&block) block.call end def just_yield yield end Benchmark.ips do |x| x.report("call") do block_call { 1 + 1 } end x.report("just yield") do just_yield { 1 + 1 } end x.compare! end ~~~ I run on Ruby 2.2.1 ~~~ Calculating ------------------------------------- call 40.754k i/100ms just yield 69.031k i/100ms ------------------------------------------------- call 814.929k (± 4.0%) i/s - 4.075M just yield 2.871M (±25.1%) i/s - 12.909M Comparison: just yield: 2871127.3 i/s call: 814929.3 i/s - 3.52x slower ~~~ -- https://bugs.ruby-lang.org/
participants (1)
-
Earlopain (Earlopain _)