Ruby: HTTPClient is Sloooooow
Is this just me? I think it must be—I am getting terrible performance using HTTPClient vs Net::HTTP. I was looking for an alternative to Net::HTTP because its API is ugly as hell, but the performance difference leaves me with no choice.
Let’s take the example of loading this blog’s last four entries using the Google AJAX Feed API. Net::HTTP consistently takes less than a second to load the results, while HTTPClient consistently takes between 10 and 15 seconds! This can’t be right, I must be doing something wrong…
Here’s the script I’m using to test:
require 'httpclient'
require 'net/http'
require 'uri'
require 'cgi'
def time(label)
t_start = Time.now.to_f
yield if block_given?
puts "#{label}: #{Time.now.to_f - t_start}s"
end
feed_url = "http://taylorbarstow.com/feed/"
url = "http://www.google.com/uds/Gfeeds?v=1.0&output=json&q=#{CGI.escape(feed_url)}"
time "Net::HTTP" do
Net::HTTP.get(URI.parse(url))
end
time "HTTPClient" do
HTTPClient.new.get_content(url)
end

