Created
August 17, 2012 07:06
-
-
Save jacegu/3376640 to your computer and use it in GitHub Desktop.
Some Benchmarks
This file contains 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 'em-http-request' #gem install em-http-request | |
require 'typhoeus' #gem install typhoeus | |
ENDPOINT = 'https://api.github.com/repos/rails/rails/issues' | |
ISSUE_PAGES = 6 | |
def benchmark(message, &code) | |
start_time = Time.now | |
code.call | |
end_time = Time.now | |
puts "It took #{end_time - start_time} seconds #{message}" | |
end | |
benchmark "getting all rails' open issues with EventMachine" do | |
EM.run do | |
@pages = 0 | |
1.upto(ISSUE_PAGES) do |page| | |
http = EM::HttpRequest.new(ENDPOINT).get query: {page: page, per_page: 100} | |
http.callback { @pages += 1; EM.stop if @pages >= ISSUE_PAGES } | |
end | |
end | |
end | |
benchmark "getting all rails' open issues with Typhoeus" do | |
1.upto(ISSUE_PAGES) do |page| | |
response = Typhoeus::Request.get(ENDPOINT, params: { page: page, per_page: 100}) | |
puts response.time | |
end | |
end | |
benchmark "getting all rails' open issues with Typhoeus' hydra" do | |
hydra = Typhoeus::Hydra.new | |
1.upto(ISSUE_PAGES) do |page| | |
request = Typhoeus::Request.new(ENDPOINT, params: { page: page, per_page: 100}) | |
request.on_complete { |response| puts response.time } | |
hydra.queue(request) | |
end | |
hydra.run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment