Sha256: a2bac8af8b551fb3aa3325b4b8b184b5a774ad1993a07040c21246478516577d

Contents?: true

Size: 691 Bytes

Versions: 70

Compression:

Stored size: 691 Bytes

Contents

class SendDispatch
  attr_reader :event_log

  def initialize
    @event_log = []
  end

  def call(event)
    handler_name = "handle_#{event.name}"
    __send__(handler_name, event) if respond_to?(handler_name)
  end

  def handle_foo(event)
    event_log << event
  end

  def handle_bar(event)
    event_log << event
  end

  def handle_baz(event)
    event_log << event
  end
end

klass = SendDispatch
event = Struct.new(:name, :source, :args)

100_000.times do
  obj = klass.new
  obj.call(e1 = event[:foo])
  obj.call(e2 = event[:bar])
  obj.call(e3 = event[:baz])
  obj.call(event[:buz])
  unless obj.event_log == [e1, e2, e3]
    raise "#{klass}: #{obj.event_log.inspect}"
  end
end

Version data entries

70 entries across 70 versions & 2 rubygems

Version Path
opal-1.8.3.rc1 benchmark/bm_dispatch_send.rb
opal-1.8.2 benchmark/bm_dispatch_send.rb
opal-1.8.1 benchmark/bm_dispatch_send.rb
opal-1.8.0 benchmark/bm_dispatch_send.rb
opal-1.8.0.beta1 benchmark/bm_dispatch_send.rb
opal-1.7.4 benchmark/bm_dispatch_send.rb
opal-1.8.0.alpha1 benchmark/bm_dispatch_send.rb
opal-1.7.3 benchmark/bm_dispatch_send.rb
opal-1.7.2 benchmark/bm_dispatch_send.rb
opal-1.7.1 benchmark/bm_dispatch_send.rb
opal-1.7.0 benchmark/bm_dispatch_send.rb
opal-1.7.0.rc1 benchmark/bm_dispatch_send.rb
opal-1.6.1 benchmark/bm_dispatch_send.rb
opal-1.6.0 benchmark/bm_dispatch_send.rb
opal-1.6.0.rc1 benchmark/bm_dispatch_send.rb
opal-1.6.0.alpha1 benchmark/bm_dispatch_send.rb
opal-1.5.1 benchmark/bm_dispatch_send.rb
opal-1.5.0 benchmark/bm_dispatch_send.rb
opal-1.5.0.rc1 benchmark/bm_dispatch_send.rb
opal-1.4.1 benchmark/bm_dispatch_send.rb