-
-
Save danmayer/6104806 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rest_client' | |
require 'net/http' | |
require 'benchmark' | |
URL = 'https://www.livingsocial.com/deals/753290-tacos-and-margaritas-for-two-or-four' | |
time = Benchmark.realtime do | |
(1..100).each { | |
url = URI.parse(URL) | |
req = Net::HTTP::Get.new(url.path) | |
res = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') {|http| http.request(req) } | |
} | |
end | |
printf("NET::HTTP => Time elapsed %0.3f seconds\n", "#{time}") | |
time = Benchmark.realtime do | |
(1..100).each { | |
RestClient.get(URL) | |
} | |
end | |
printf("RestClient => Time elapsed %0.3f seconds\n", "#{time}") |
Yeah so looks like Adam Keys pointed out it likely is just rest-client follows redirects by default and Net::Http doesn't. Doug Ramsay confirmed that net http just immediately returns the 301
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmmm confused why using rest client head requests on a bitly url has much worse perf with rest client
https://gist.github.com/adriaant/716155
(modified the original gist to do a 100.each iterations, bitly URL and HEAD requests)
NET::HTTP => Time elapsed 3.781 seconds
RestClient => Time elapsed 82.085 seconds
While my updated gist above with a get request to a non bitly URL shows little difference between rest-client and Net::HTTP?
[master][~/projects/deals] ruby benchmark.rb
NET::HTTP => Time elapsed 37.432 seconds
RestClient => Time elapsed 32.331 seconds
Oddly enough if I change the URL back to the original bitly url, 'http://bit.ly/4okpb2' and run this with the 100 get requests each, again rest-client is much faster when hitting bitly
NET::HTTP => Time elapsed 3.376 seconds
RestClient => Time elapsed 112.337 seconds
Anyone got ideas as to why?