Created
October 24, 2013 08:32
-
-
Save anvyzhang/7133339 to your computer and use it in GitHub Desktop.
Test async http request vs sync http request
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 'rubygems' | |
require 'eventmachine' | |
require 'em-http-request' | |
require 'patron' | |
f = Time.now | |
arr = [] | |
j = 50 | |
EventMachine.run do | |
(1..50).each{|i| | |
arr[i] = EventMachine::HttpRequest.new('http://csdn.net/').get | |
arr[i].callback { | |
j -= 1 | |
EventMachine.stop if j == 0 | |
} | |
} | |
end | |
puts "1--time--------#{(Time.now-f)}" | |
f = Time.now | |
s = Patron::Session.new | |
s.timeout = 60 | |
s.base_url = 'http://csdn.net' | |
(1..50).each{|i| | |
s.get("/").body | |
} | |
puts "2--time--------#{(Time.now-f)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment