Skip to content

Instantly share code, notes, and snippets.

@danmayer
Forked from adriaant/nethttp_vs_restclient.rb
Last active December 20, 2015 08:59
Show Gist options
  • Save danmayer/6104806 to your computer and use it in GitHub Desktop.
Save danmayer/6104806 to your computer and use it in GitHub Desktop.
#!/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}")
@danmayer
Copy link
Author

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