Sha256: 29c4f9c778f8a6083ee20f3c898f6e0edd678276516fc6a5e522b96e44d0d454

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'celluloid/io'
require 'benchmark/ips'

class ExampleActor
  include Celluloid::IO

  def initialize
    @condition = Celluloid::Condition.new
  end

  def example_method; end

  def finished
    @condition.signal
  end

  def wait_until_finished
    @condition.wait
  end
end

example_actor = ExampleActor.new
mailbox = Celluloid::IO::Mailbox.new

latch_in, latch_out = Queue.new, Queue.new
latch = Thread.new do
  while true
    n = latch_in.pop
    for i in 0...n; mailbox.receive; end
    latch_out << :done
  end
end

Benchmark.ips do |ips|
  ips.report("spawn")       { ExampleActor.new.terminate }

  ips.report("calls")       { example_actor.example_method }

  ips.report("async calls") do |n|
    waiter = example_actor.future.wait_until_finished

    for i in 1..n; example_actor.async.example_method; end
    example_actor.async.finished

    waiter.value
  end

# Deadlocking o_O
=begin
  ips.report("messages") do |n|
    latch_in << n
    for i in 0...n; mailbox << :message; end
    latch_out.pop
  end
=end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
celluloid-io-0.17.1 benchmarks/actor.rb
celluloid-io-0.17.0 benchmarks/actor.rb
celluloid-io-0.16.5.pre0 benchmarks/actor.rb
celluloid-io-0.16.2 benchmarks/actor.rb
celluloid-io-0.16.1 benchmarks/actor.rb
celluloid-io-0.16.0 benchmarks/actor.rb
celluloid-io-0.16.0.pre2 benchmarks/actor.rb
celluloid-io-0.16.0.pre benchmarks/actor.rb
celluloid-io-0.15.0 benchmarks/actor.rb
celluloid-io-0.15.0.pre2 benchmarks/actor.rb
celluloid-io-0.15.0.pre benchmarks/actor.rb