Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created December 14, 2017 17:48
Show Gist options
  • Save philsturgeon/f4003f5ae14ca76665d8e002824a50aa to your computer and use it in GitHub Desktop.
Save philsturgeon/f4003f5ae14ca76665d8e002824a50aa to your computer and use it in GitHub Desktop.
Faraday Adapters Benchmark
require 'benchmark'
require 'json'
require 'faraday'
require 'typhoeus'
require 'patron'
require 'httpclient'
require 'typhoeus/adapters/faraday'
n = 100
params = {
'foo' => 'bar'
# an actual request that does a bunch of stuff
}
adapters = [:net_http, :net_http_persistent, :patron, :httpclient, :typhoeus]
def create_client(adapter)
host = 'https://example.wework.com/'
Faraday.new(url: host, ssl: { verify: false }) do |conn|
conn.adapter adapter
end
end
Benchmark.bm(20) do |x|
adapters.each do |adapter|
x.report("#{adapter}:") do
client = create_client(adapter)
n.times do |i|
client.post do |req|
req.url "/endpoint?i=#{i}"
req.headers['Content-Type'] = 'application/json'
req.body = JSON.generate(params)
end
end
end
end
end
source 'https://rubygems.org'
gem 'faraday'
gem 'net-http-persistent'
gem 'typhoeus'
gem 'patron'
gem 'httpclient'
gem 'net-http2'
user system total real
net_http: 0.910000 0.190000 1.100000 ( 9.382847)
net_http_persistent: 0.980000 0.170000 1.150000 ( 9.245193)
patron: 0.150000 0.110000 0.260000 ( 2.233322)
httpclient: 0.150000 0.100000 0.250000 ( 2.142556)
typhoeus: 0.120000 0.070000 0.190000 ( 2.138841)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment