typhoeus/ethon — pull request #48 by koppenheim (2013-04-13 20:05:59+00:00)
Title: Handful of performance optimizations

Could use a second (third?) pair of eyes on these. Hence the pull request instead of a direct commit.

Here's the benchmark @richievos and I have been using (more-or-less)

require 'benchmark'
require 'cgi'

def benchmark(msg, iterations=1000, &block)
puts "#{msg} (n=#{iterations})"
GC.start
#RubyProf.start
times = Benchmark.ms do
iterations.times(&block)
end
#profile = RubyProf.stop

puts "\ttime: #{(times / iterations.to_f).round(2)}"
#printer = RubyProf::GraphPrinter.new(profile)
#printer.print(STDOUT)
#printer = RubyProf::CallTreePrinter.new(profile)
#printer.print(File.new('/var/tmp/rubyprof.output', "w"))
end

def run
puts "===Typhoeus version: #{Typhoeus::VERSION}==="
hydra = Typhoeus::Hydra.new
benchmark("making couple requests") do
request = Typhoeus::Request.new("http://internal-url.company.com?with=params", :method => :get)
hydra.queue(request)
hydra.run
end
end

run

Before (pasting one sample run of many):

===Typhoeus version: 0.6.2===
making couple requests (n=1000)
time: 3.02

After (one sample of many similar results):

===Typhoeus version: 0.6.2===
making couple requests (n=1000)
time: 2.02