Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handful of performance optimizations #48

Merged
merged 5 commits into from
Apr 14, 2013
Merged

Handful of performance optimizations #48

merged 5 commits into from
Apr 14, 2013

Conversation

koppenheim
Copy link
Contributor

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

richievos and others added 3 commits April 13, 2013 12:31
method(:x).call => send(:x)
Don't instantiate strings for logging when we don't need to.
Do recursion with real methods instead of procs, since its faster and avoids creating procs
Instantiate less memorypointers
@hanshasselberg
Copy link
Member

Looks good to me - except for the failing specs.
I'm impressed by the performance gain you archived with it!!

koppenheim added a commit that referenced this pull request Apr 14, 2013
Handful of performance optimizations
@koppenheim koppenheim merged commit 65aa32e into typhoeus:master Apr 14, 2013
@craiglittle
Copy link
Member

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants