Skip to content

Instantly share code, notes, and snippets.

@anvyzhang
Created October 24, 2013 08:32
Show Gist options
  • Save anvyzhang/7133339 to your computer and use it in GitHub Desktop.
Save anvyzhang/7133339 to your computer and use it in GitHub Desktop.
Test async http request vs sync http request
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