Sha256: 18fb39a7b13a1326b7259db1955d179deeeb02610774dc5511765a3a7e00ac88

Contents?: true

Size: 1.37 KB

Versions: 6809

Compression:

Stored size: 1.37 KB

Contents

require 'typhoeus'
require 'net/http'
require 'open-uri'
require 'benchmark'

URL = "http://localhost:300"
hydra = Typhoeus::Hydra.new(max_concurrency: 3)

if defined? require_relative
  require_relative '../spec/support/localhost_server.rb'
  require_relative '../spec/support/server.rb'
else
  require '../spec/support/localhost_server.rb'
  require '../spec/support/server.rb'
end
LocalhostServer.new(TESTSERVER.new, 3000)
LocalhostServer.new(TESTSERVER.new, 3001)
LocalhostServer.new(TESTSERVER.new, 3002)

def url_for(i)
  "#{URL}#{i%3}/"
end

Benchmark.bm do |bm|

  [1000].each do |calls|
    puts "[ #{calls} requests ]"

    bm.report("net/http        ") do
      calls.times do |i|
        uri = URI.parse(url_for(i))
        Net::HTTP.get_response(uri)
      end
    end

    bm.report("open            ") do
      calls.times do |i|
        open(url_for(i))
      end
    end

    bm.report("request         ") do
      calls.times do |i|
        Typhoeus::Request.get(url_for(i))
      end
    end

    bm.report("hydra           ") do
      calls.times do |i|
        hydra.queue(Typhoeus::Request.new(url_for(i)))
      end
      hydra.run
    end

    bm.report("hydra memoize   ") do
      Typhoeus::Config.memoize = true
      calls.times do |i|
        hydra.queue(Typhoeus::Request.new(url_for(i)))
      end
      hydra.run
      Typhoeus::Config.memoize = false
    end
  end
end

Version data entries

6,809 entries across 6,806 versions & 27 rubygems

Version Path
cybrid_api_id_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_id_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_id_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
ory-client-1.15.17 vendor/bundle/ruby/3.1.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_id_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_id_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_id_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_bank_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb
cybrid_api_organization_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/perf/vs_nethttp.rb