Skip to content

Instantly share code, notes, and snippets.

@krasio
Forked from phiggins/excon benchmark
Created December 15, 2011 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krasio/1481255 to your computer and use it in GitHub Desktop.
Save krasio/1481255 to your computer and use it in GitHub Desktop.
excon benchmark vs google
$ ruby benchmarks/excon_vs_google.rb
[em-http-request, HTTParty, Net::HTTP, Net::HTTP (persistent), open-uri, RestClient, StreamlyFFI (persistent), Typhoeus, Excon, Excon (persistent)]
+--------------------------+-----------+
| tach | total |
+--------------------------+-----------+
| Excon | 7.614298 |
+--------------------------+-----------+
| Typhoeus | 7.723362 |
+--------------------------+-----------+
| StreamlyFFI (persistent) | 7.778743 |
+--------------------------+-----------+
| Excon (persistent) | 8.178862 |
+--------------------------+-----------+
| open-uri | 17.996636 |
+--------------------------+-----------+
| RestClient | 18.041814 |
+--------------------------+-----------+
| Net::HTTP | 18.256657 |
+--------------------------+-----------+
| Net::HTTP (persistent) | 18.293269 |
+--------------------------+-----------+
| em-http-request | 18.554890 |
+--------------------------+-----------+
| HTTParty | 18.624778 |
+--------------------------+-----------+
require 'rubygems' if RUBY_VERSION < '1.9'
require 'bundler'
Bundler.require(:default)
Bundler.require(:benchmark)
require File.join(File.dirname(__FILE__), '..', 'lib', 'excon')
require 'em-http-request'
require 'httparty'
require 'net/http'
require 'open-uri'
require 'rest_client'
require 'tach'
require 'typhoeus'
url = "http://www.google.com"
Tach.meter(100) do
tach('em-http-request') do
EventMachine.run {
http = EventMachine::HttpRequest.new(url).get
http.callback {
http.response
EventMachine.stop
}
}
end
tach('HTTParty') do
HTTParty.get(url).body
end
tach('Net::HTTP') do
# Net::HTTP.get('localhost', '/data/1000', 9292)
Net::HTTP.start('www.google.com', 80) {|http| http.get('/').body }
end
Net::HTTP.start('www.google.com', 80) do |http|
tach('Net::HTTP (persistent)') do
http.get('/').body
end
end
tach('open-uri') do
open(url).read
end
tach('RestClient') do
RestClient.get(url)
end
streamly = StreamlyFFI::Connection.new
tach('StreamlyFFI (persistent)') do
streamly.get(url)
end
tach('Typhoeus') do
Typhoeus::Request.get(url).body
end
tach('Excon') do
Excon.get(url).body
end
excon = Excon.new(url)
tach('Excon (persistent)') do
excon.request(:method => 'get').body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment