Created
December 3, 2020 12:10
-
-
Save plus3x/be5aef6c440e8eaf1a6e5807601a8811 to your computer and use it in GitHub Desktop.
Ruby HTTP gem performance
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
require 'benchmark' | |
uri = URI('http://stackoverflow.com/questions/30899019/') | |
n = 10 | |
require 'net/http' | |
puts | |
puts "Net::HTTP:" | |
Benchmark.bm do |b| | |
b.report { n.times { Net::HTTP.get(uri) } } | |
b.report { threads = Array.new(n) { Thread.new { Net::HTTP.get(uri) } }; threads.each(&:join) } | |
end | |
require 'typhoeus' | |
puts | |
puts "Typhoeus:" | |
Benchmark.bm do |b| | |
b.report { n.times { Typhoeus.get(uri) } } | |
b.report do | |
threads = Array.new(n) { Thread.new { Typhoeus.get(uri) } }; threads.each(&:join) | |
end | |
b.report do | |
hydra = Typhoeus::Hydra.new | |
n.times { hydra.queue(Typhoeus::Request.new(uri, followlocation: true)) } | |
hydra.run | |
end | |
end | |
require 'http' | |
puts | |
puts "HTTP.rb:" | |
Benchmark.bm do |b| | |
b.report { n.times { HTTP.get(uri) } } | |
b.report do | |
threads = Array.new(n) { Thread.new { HTTP.get(uri) } }; threads.each(&:join) | |
end | |
end | |
require 'curb' | |
puts | |
puts "curb:" | |
Benchmark.bm do |b| | |
b.report { n.times { Curl.get(uri) } } | |
b.report do | |
threads = Array.new(n) { Thread.new { Curl.get(uri) } }; threads.each(&:join) | |
end | |
end | |
puts | |
__END__ | |
Net::HTTP: | |
user system total real | |
0.008941 0.004792 0.013733 ( 1.734035) | |
0.009222 0.007354 0.016576 ( 0.189986) | |
Typhoeus: | |
user system total real | |
0.007242 0.001575 0.008817 ( 1.279969) | |
0.033138 0.005785 0.038923 ( 0.187063) | |
0.127697 0.051684 0.179381 ( 3.540030) | |
HTTP.rb: | |
user system total real | |
0.013245 0.003254 0.016499 ( 1.874882) | |
0.012030 0.004290 0.016320 ( 0.193205) | |
curb: | |
user system total real | |
0.002318 0.001749 0.004067 ( 2.828735) | |
0.004125 0.006173 0.010298 ( 0.308138) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment