Created
November 13, 2012 00:33
-
-
Save brookemckim/4063052 to your computer and use it in GitHub Desktop.
Comparison of using Celluloid to do GETs over HTTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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