Skip to content

Instantly share code, notes, and snippets.

@brookemckim
Created November 13, 2012 00:33
Show Gist options
  • Save brookemckim/4063052 to your computer and use it in GitHub Desktop.
Save brookemckim/4063052 to your computer and use it in GitHub Desktop.
Comparison of using Celluloid to do GETs over HTTP
require 'open-uri'
Benchmark.measure {
URI.parse('http://yahoo.com').read
URI.parse('http://yahoo.com').read
URI.parse('http://yahoo.com').read
}
# => 0.080000 0.020000 0.100000 ( 6.717970)
require 'open-uri'
require 'celluloid'
class CellularGet
include Celluloid
def get(url)
URI.parse(url).read
end
end
Benchmark.measure {
futures = 3.times.map do
CellularGet.new.future.get('http://yahoo.com')
end
futures.map(&:value)
}
# => 0.070000 0.030000 0.100000 ( 3.078119)
require 'open-uri'
require 'celluloid'
class CellularGet
include Celluloid
def get(url)
URI.parse(url).read
end
end
Benchmark.measure {
pool = CellularGet.pool
futures = 3.times.map do
pool.future.get("http://yahoo.com")
end
futures.map(&:value)
}
# => 0.090000 0.030000 0.120000 ( 2.683866)
require 'thread'
threads = []
Benchmark.measure {
3.times do
threads << Thread.new do
URI.parse('http://yahoo.com').read
end
end
threads.each { |t| t.join }
}
# => 0.070000 0.020000 0.090000 ( 3.037022)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment