Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick-and-dirty benchmarking of Rocketman vs Wisper vs Dry::Events

Not meaning to throw shade on Wisper 2.0.0; it's a very mature, reliable, widely-used Pub/Sub system. It's not the fastest, though; benchmarking it against against RocketMan 0.1.1 and dry-events 0.2.0 gives the following results:

Results:

$ ./benchmarks.rb
Rehearsal -------------------------------------------------
RocketMan       0.150000   0.010000   0.160000 (  0.163206)
Wisper          2.330000   0.350000   2.680000 (  2.994349)
Dry::Events 1   1.490000   0.290000   1.780000 (  1.788510)
Dry::Events 2   1.600000   0.250000   1.850000 (  1.847081)
---------------------------------------- total: 6.470000sec

                    user     system      total        real
RocketMan       0.160000   0.000000   0.160000 (  0.159497)
Wisper          2.300000   0.410000   2.710000 (  2.759654)
Dry::Events 1   1.400000   0.330000   1.730000 (  1.733275)
Dry::Events 2   1.440000   0.320000   1.760000 (  1.758974)
$ ./benchmarks.rb
Rehearsal -------------------------------------------------
RocketMan       0.140000   0.010000   0.150000 (  0.157267)
Wisper          2.380000   0.300000   2.680000 (  3.046776)
Dry::Events 1   1.510000   0.290000   1.800000 (  1.804191)
Dry::Events 2   1.400000   0.330000   1.730000 (  1.743957)
---------------------------------------- total: 6.360000sec

                    user     system      total        real
RocketMan       0.170000   0.010000   0.180000 (  0.174773)
Wisper          2.300000   0.330000   2.630000 (  2.677181)
Dry::Events 1   1.440000   0.280000   1.720000 (  1.731817)
Dry::Events 2   1.490000   0.330000   1.820000 (  1.827146)
$ 

Notes:

  1. This adds two benchmarks for dry-events 0.2.0, which was not previously included in the benchmarks; see notes below for details
  2. The ridiculously-high times for the Wisper benchmark previously published are no longer reproducible;

The benchmark labelled Dry::Events 1 uses event listeners, whereas Dry::Events 2 uses block-based subscribers. The two techniques are closely matched in speed relative to each other.

The code used to provide these benchmarks is below. Feel free to suggest improvements.

#!/usr/bin/env ruby
require 'rocketman';
require 'benchmark';
require 'logger'
require 'wisper'
require 'dry/events/listener'
require 'dry/events/publisher' # redundant; required by 'dry/events/listener'
module DE
class Producer
include Dry::Events::Publisher['main.app']
register_event('hello')
end
class Consumer
def on_hello(event)
Logger.new('/dev/null').info('.')
end
end
end
module RM
class Producer
include Rocketman::Producer
def hello_world
emit :hello, payload: { success: true }
end
end
class Consumer
extend Rocketman::Consumer
on_event :hello do |payload|
Logger.new('/dev/null').info('.')
end
end
end
module W
class Producer
include ::Wisper::Publisher
def call
publish(:hello, true) # #publish is alias of #broadcast
end
end
class Consumer
def hello(flag)
Logger.new('/dev/null').info('.')
end
end
end
def run_benchmarks
limit = 100_000
consumer = RM::Consumer.new
producer = RM::Producer.new
receiver = W::Consumer.new
sender = W::Producer.new
publisher = DE::Producer.new
listener = DE::Consumer.new
publisher2 = DE::Producer.new
publisher2.subscribe('hello') do |event|
Logger.new('/dev/null').info('.')
end
sender.subscribe(receiver)
publisher.subscribe(listener)
Benchmark.bmbm do |x|
x.report('RocketMan') { (1..limit).each { producer.hello_world; } }
x.report('Wisper') { (1..limit).each { sender.call; } }
x.report('Dry::Events 1') { (1..limit).each { publisher.publish('hello', success: true); } }
x.report('Dry::Events 2') do
(1..limit).each do
publisher2.publish('hello', success: true);
end
end
end
end
run_benchmarks if $0.to_s.match?(/\.rb$/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.