Skip to content

Instantly share code, notes, and snippets.

@lipowen
Forked from phiggins/excon benchmark
Created May 3, 2017 08:25
Show Gist options
  • Save lipowen/2e97a448f87a50a82b8c957a87818166 to your computer and use it in GitHub Desktop.
Save lipowen/2e97a448f87a50a82b8c957a87818166 to your computer and use it in GitHub Desktop.

Revisions

  1. @phiggins phiggins created this gist Dec 1, 2010.
    27 changes: 27 additions & 0 deletions excon benchmark
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    $ 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 |
    +--------------------------+-----------+
    73 changes: 73 additions & 0 deletions excon_vs_google.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    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
    Empty file added gistfile3.txt
    Empty file.