Skip to content

Commit

Permalink
Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Mar 29, 2012
1 parent e4fe2d7 commit c2a5a5e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
6 changes: 2 additions & 4 deletions Rakefile
@@ -1,7 +1,5 @@
#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
Dir["tasks/**/*.task"].each { |task| load task }

RSpec::Core::RakeTask.new

task :default => :spec
task :default => :spec
35 changes: 35 additions & 0 deletions benchmarks/actor.rb
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby

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

class ExampleActor
include Celluloid::IO
def example_method; end
end

example_actor = ExampleActor.new
mailbox = Celluloid::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") { example_actor.example_method! }

ips.report("messages") do |n|
latch_in << n
for i in 0..n; mailbox << :message; end
latch_out.pop
end
end
14 changes: 14 additions & 0 deletions benchmarks/ring.rb
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'celluloid'
require 'benchmark/ips'
require File.expand_path("../../examples/ring", __FILE__)

# 512-node ring
ring = Ring.new 512

Benchmark.ips do |ips|
ips.report("ring-around") { |n| ring.run n }
end
1 change: 1 addition & 0 deletions celluloid-io.gemspec
Expand Up @@ -20,4 +20,5 @@ Gem::Specification.new do |gem|

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'benchmark_suite'
end
2 changes: 1 addition & 1 deletion spec/celluloid/io/actor_spec.rb
Expand Up @@ -2,4 +2,4 @@

describe Celluloid::IO do
it_behaves_like "a Celluloid Actor", Celluloid::IO
end
end
19 changes: 19 additions & 0 deletions tasks/benchmarks.task
@@ -0,0 +1,19 @@
require 'timeout'

desc "Run Celluloid benchmarks"
task :benchmark do
# Travis has an out-of-date version of rbx that rashes on the benchmarks
exit 0 if ENV['CI'] and RUBY_ENGINE == 'rbx'

begin
Timeout.timeout(120) do
glob = File.expand_path("../../benchmarks/*.rb", __FILE__)
Dir[glob].each { |benchmark| load benchmark }
end
rescue Exception, Timeout::Error => ex
puts "ERROR: Couldn't complete benchmark: #{ex.class}: #{ex}"
puts " #{ex.backtrace.join("\n ")}"

exit 1 unless ENV['CI'] # Hax for running benchmarks on Travis
end
end
7 changes: 7 additions & 0 deletions tasks/rspec.task
@@ -0,0 +1,7 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new

RSpec::Core::RakeTask.new(:rcov) do |task|
task.rcov = true
end

0 comments on commit c2a5a5e

Please sign in to comment.