Created
August 7, 2015 08:58
-
-
Save weapp/13fa3885a798883caec5 to your computer and use it in GitHub Desktop.
Faraday backends
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/ips' | |
require 'faraday' | |
require 'excon' | |
require 'typhoeus'#, '~> 0.3.3' | |
require 'patron' | |
require 'net-http-persistent' | |
default_adapter = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP | |
end | |
net_http = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter :net_http | |
end | |
excon = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter :excon | |
end | |
typhoeus = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter :typhoeus | |
end | |
patron = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter :patron | |
end | |
net_http_persistent = Faraday.new(:url => 'http://localhost') do |faraday| | |
faraday.adapter :net_http_persistent | |
end | |
Benchmark.ips do |x| | |
x.time = 5 | |
x.warmup = 2 | |
x.report("default_adapter") { default_adapter.get '/errors/404.json' } | |
x.report("net_http") { net_http.get '/errors/404.json' } | |
x.report("excon") { excon.get '/errors/404.json' } | |
x.report("typhoeus") { typhoeus.get '/errors/404.json'} | |
x.report("patron") { patron.get '/errors/404.json'} | |
x.report("net_http_persistent") { net_http_persistent.get '/errors/404.json'} | |
x.compare! | |
end | |
# Calculating ------------------------------------- | |
# default_adapter 105.000 i/100ms | |
# net_http 106.000 i/100ms | |
# excon 74.000 i/100ms | |
# typhoeus 206.000 i/100ms | |
# patron 216.000 i/100ms | |
# net_http_persistent 142.000 i/100ms | |
# ------------------------------------------------- | |
# default_adapter 1.037k (± 6.1%) i/s - 5.250k | |
# net_http 978.088 (±11.0%) i/s - 4.876k | |
# excon 518.018 (±57.3%) i/s - 296.000 in 15.169147s | |
# typhoeus 1.991k (±11.7%) i/s - 9.682k | |
# patron 2.029k (±22.1%) i/s - 8.856k in 5.271006s | |
# net_http_persistent 1.500k (±20.7%) i/s - 6.674k | |
# Comparison: | |
# patron: 2028.7 i/s | |
# typhoeus: 1991.1 i/s - 1.02x slower | |
# net_http_persistent: 1499.7 i/s - 1.35x slower | |
# default_adapter: 1037.0 i/s - 1.96x slower | |
# net_http: 978.1 i/s - 2.07x slower | |
# excon: 518.0 i/s - 3.92x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment