[#68478] Looking for MRI projects for Ruby Google Summer of Code 2015 — Tony Arcieri <bascule@...>

Hi ruby-core,

10 messages 2015/03/10

[ruby-core:68558] [Ruby trunk - Misc #10983] [Open] Why blocks make Ruby methods 439% slower ?

From: Sergey.V.Ezhov@...
Date: 2015-03-19 09:03:46 UTC
List: ruby-core #68558
Issue #10983 has been reported by =D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9 =D0=
=95.

----------------------------------------
Misc #10983: Why blocks make Ruby methods 439% slower ?
https://bugs.ruby-lang.org/issues/10983

* Author: =D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9 =D0=95
* Status: Open
* Priority: Normal
* Assignee:=20
----------------------------------------
https://www.omniref.com/ruby/2.2.0/symbols/Proc/yield#annotation=3D4087638&=
line=3D711&hn=3D1


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 (=C2=B1 4.0%) i/s -      4.075M
          just yield      2.871M (=C2=B125.1%) i/s -     12.909M

Comparison:
          just yield:  2871127.3 i/s
                call:   814929.3 i/s - 3.52x slower




--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next