Skip to content

Instantly share code, notes, and snippets.

@ifyouseewendy
Created October 19, 2014 09:53
Show Gist options
  • Save ifyouseewendy/0fdbd8f63bf870e22b90 to your computer and use it in GitHub Desktop.
Save ifyouseewendy/0fdbd8f63bf870e22b90 to your computer and use it in GitHub Desktop.
benchmark on faraday with net/http, em-http-request and typhoeus.
require 'benchmark'
require 'faraday'
require 'faraday_middleware'
class Wendi
def initialize(app)
@app = app
end
def call(env)
puts 'wendi requesting...'
@app.call(env).on_complete do
puts 'wendi responsing...'
end
end
end
conn = Faraday.new(:url => 'http://localhost:3000') do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.response :json, :content_type => /\bjson$/
faraday.use Wendi
faraday.adapter :em_http
end
## GET ##
puts Benchmark.measure {
3000.times{
conn.get '/hello.json' # { status: "ok", msg: "hello" }
}
}
# 6.990000 1.280000 8.270000 ( 24.286771)
require 'benchmark'
require 'faraday'
require 'faraday_middleware'
class Wendi
def initialize(app)
@app = app
end
def call(env)
puts 'wendi requesting...'
@app.call(env).on_complete do
puts 'wendi responsing...'
end
end
end
conn = Faraday.new(:url => 'http://localhost:3000') do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.response :json, :content_type => /\bjson$/
faraday.use Wendi
faraday.adapter Faraday.default_adapter
end
## GET ##
puts Benchmark.measure {
3000.times{
conn.get '/hello.json' # { status: "ok", msg: "hello" }
}
}
# 4.740000 1.380000 6.120000 ( 24.986561)
require 'benchmark'
require 'faraday'
require 'faraday_middleware'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
class Wendi
def initialize(app)
@app = app
end
def call(env)
puts 'wendi requesting...'
@app.call(env).on_complete do
puts 'wendi responsing...'
end
end
end
conn = Faraday.new(:url => 'http://localhost:3000') do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.response :json, :content_type => /\bjson$/
faraday.use Wendi
faraday.adapter :typhoeus
end
## GET ##
puts Benchmark.measure {
300.times {
conn.in_parallel{
10.times{
conn.get '/hello.json' # { status: "ok", msg: "hello" }
}
}
}
}
# 5.120000 0.500000 5.620000 ( 18.206284)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment