Skip to content

Instantly share code, notes, and snippets.

@philsturgeon philsturgeon/1-output.txt Secret
Last active Jan 2, 2018

Embed
What would you like to do?
HTTP 2 Client Call Benchmark
user system total real
faraday (http/1.1): 0.260000 0.030000 0.290000 ( 12.647877)
net-http2: 0.080000 0.010000 0.090000 ( 2.466356)
require 'benchmark'
require 'json'
require 'faraday'
require 'net-http2'
n = 20
host = 'https://secret.example.com/'
params = {
foo: 'something'
}
Benchmark.bm(15) do |x|
x.report("faraday (http/1.1):") do
client = Faraday.new(url: host, ssl: {verify: false}) do |conn|
conn.adapter :net_http
end
n.times do |i|
client.post do |req|
req.url '/check'
req.headers['Content-Type'] = 'application/json'
req.body = JSON.generate(params)
end
end
end
x.report("net-http2:") do
client = NetHttp2::Client.new(host)
n.times do
# prepare request
request = client.prepare_request(:post, '/check', body: JSON.generate(params), headers: {
'content-type' => 'application/json'
})
client.call_async(request)
end
# Wait for all outgoing stream to be closed
client.join
# close the connection
client.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.