diff options
Diffstat (limited to 'lib/vendor/excon/benchmarks')
18 files changed, 1289 insertions, 0 deletions
diff --git a/lib/vendor/excon/benchmarks/class_vs_lambda.rb b/lib/vendor/excon/benchmarks/class_vs_lambda.rb new file mode 100644 index 0000000..6f902ee --- /dev/null +++ b/lib/vendor/excon/benchmarks/class_vs_lambda.rb @@ -0,0 +1,50 @@ +require 'rubygems' +require 'tach' + +class Concatenator + def initialize(string) + @string = string + end + + def call(data) + @string << data + end +end + +string = "0123456789ABCDEF" + +Tach.meter(100_000) do + tach('class') do + s = "" + obj = Concatenator.new(s) + 10.times { obj.call(string) } + end + + tach('lambda') do + s = "" + obj = lambda {|data| s << data } + 10.times { obj.call(string) } + end +end + +# ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux] +# +# +--------+----------+ +# | tach | total | +# +--------+----------+ +# | class | 1.450284 | +# +--------+----------+ +# | lambda | 2.506496 | +# +--------+----------+ + +# ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux] +# +# +--------+----------+ +# | tach | total | +# +--------+----------+ +# | class | 1.373917 | +# +--------+----------+ +# | lambda | 2.589384 | +# +--------+----------+ + + diff --git a/lib/vendor/excon/benchmarks/concat_vs_insert.rb b/lib/vendor/excon/benchmarks/concat_vs_insert.rb new file mode 100644 index 0000000..237a973 --- /dev/null +++ b/lib/vendor/excon/benchmarks/concat_vs_insert.rb @@ -0,0 +1,21 @@ +require 'rubygems' +require 'tach' + +Tach.meter(1_000_000) do + tach('concat') do + path = 'path' + path = '/' << path + end + tach('insert') do + path = 'path' + path.insert(0, '/') + end +end + +# +--------+----------+ +# | tach | total | +# +--------+----------+ +# | insert | 0.974036 | +# +--------+----------+ +# | concat | 0.998904 | +# +--------+----------+
\ No newline at end of file diff --git a/lib/vendor/excon/benchmarks/concat_vs_interpolate.rb b/lib/vendor/excon/benchmarks/concat_vs_interpolate.rb new file mode 100644 index 0000000..8a24388 --- /dev/null +++ b/lib/vendor/excon/benchmarks/concat_vs_interpolate.rb @@ -0,0 +1,22 @@ +require 'rubygems' +require 'tach' + +key = 'Content-Length' +value = '100' +Tach.meter(1_000) do + tach('concat') do + temp = '' + temp << key << ': ' << value << "\r\n" + end + tach('interpolate') do + "#{key}: #{value}\r\n" + end +end + +# +-------------+----------+ +# | tach | total | +# +-------------+----------+ +# | interpolate | 0.000404 | +# +-------------+----------+ +# | concat | 0.000564 | +# +-------------+----------+ diff --git a/lib/vendor/excon/benchmarks/cr_lf.rb b/lib/vendor/excon/benchmarks/cr_lf.rb new file mode 100644 index 0000000..77adc33 --- /dev/null +++ b/lib/vendor/excon/benchmarks/cr_lf.rb @@ -0,0 +1,21 @@ +require 'rubygems' +require 'tach' + +CR_LF = "\r\n" + +Tach.meter(1_000_000) do + tach('constant') do + '' << CR_LF + end + tach('string') do + '' << "\r\n" + end +end + +# +----------+----------+ +# | tach | total | +# +----------+----------+ +# | constant | 0.819885 | +# +----------+----------+ +# | string | 0.893602 | +# +----------+----------+
\ No newline at end of file diff --git a/lib/vendor/excon/benchmarks/downcase-eq-eq_vs_casecmp.rb b/lib/vendor/excon/benchmarks/downcase-eq-eq_vs_casecmp.rb new file mode 100644 index 0000000..b36e993 --- /dev/null +++ b/lib/vendor/excon/benchmarks/downcase-eq-eq_vs_casecmp.rb @@ -0,0 +1,169 @@ +# Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell + +require 'benchmark' + +iters = 1000000 + +comp = "hello" +hello = "HelLo" + +puts 'String#downcase == vs. String#casecmp' +Benchmark.bmbm do |x| + x.report('String#downcase1') do + iters.times.each do + hello.downcase == comp + end + end + + x.report('String#downcase2') do + iters.times.each do + "HelLo".downcase == "hello" + end + end + + x.report('String#downcase3') do + iters.times.each do + var = "HelLo" + var.downcase! + var == "hello" + end + end + + x.report('casecmp1') do + iters.times.each do + hello.casecmp(comp).zero? + end + end + + x.report('casecmp1-1') do + iters.times.each do + hello.casecmp(comp) == 0 + end + end + + x.report('casecmp2') do + iters.times.each do + "HelLo".casecmp(comp).zero? + end + end + + x.report('casecmp2-1') do + iters.times.each do + "HelLo".casecmp(comp) == 0 + end + end +end + +=begin +rvm exec bash -c 'echo && echo $RUBY_VERSION && echo && ruby downcase-eq-eq_vs_casecmp.rb' + +jruby-1.5.6 + +String#downcase == vs. String#casecmp +Rehearsal ---------------------------------------------------- +String#downcase1 0.461000 0.000000 0.461000 ( 0.387000) +String#downcase2 0.269000 0.000000 0.269000 ( 0.269000) +String#downcase3 0.224000 0.000000 0.224000 ( 0.224000) +casecmp1 0.157000 0.000000 0.157000 ( 0.157000) +casecmp1-1 0.153000 0.000000 0.153000 ( 0.153000) +casecmp2 0.163000 0.000000 0.163000 ( 0.163000) +casecmp2-1 0.163000 0.000000 0.163000 ( 0.163000) +------------------------------------------- total: 1.590000sec + + user system total real +String#downcase1 0.190000 0.000000 0.190000 ( 0.191000) +String#downcase2 0.225000 0.000000 0.225000 ( 0.225000) +String#downcase3 0.190000 0.000000 0.190000 ( 0.190000) +casecmp1 0.125000 0.000000 0.125000 ( 0.125000) +casecmp1-1 0.127000 0.000000 0.127000 ( 0.127000) +casecmp2 0.144000 0.000000 0.144000 ( 0.144000) +casecmp2-1 0.147000 0.000000 0.147000 ( 0.147000) + +macruby-0.7.1 + +String#downcase == vs. String#casecmp +Rehearsal ---------------------------------------------------- +String#downcase1 2.340000 0.040000 2.380000 ( 1.765141) +String#downcase2 5.510000 0.100000 5.610000 ( 3.893249) +String#downcase3 4.200000 0.080000 4.280000 ( 3.031621) +casecmp1 0.270000 0.000000 0.270000 ( 0.267613) +casecmp1-1 0.190000 0.000000 0.190000 ( 0.188848) +casecmp2 1.450000 0.020000 1.470000 ( 1.027956) +casecmp2-1 1.380000 0.030000 1.410000 ( 0.951474) +------------------------------------------ total: 15.610000sec + + user system total real +String#downcase1 2.350000 0.040000 2.390000 ( 1.774292) +String#downcase2 5.890000 0.120000 6.010000 ( 4.214038) +String#downcase3 4.530000 0.090000 4.620000 ( 3.286059) +casecmp1 0.270000 0.000000 0.270000 ( 0.271119) +casecmp1-1 0.190000 0.000000 0.190000 ( 0.189462) +casecmp2 1.540000 0.030000 1.570000 ( 1.104751) +casecmp2-1 1.440000 0.030000 1.470000 ( 0.999689) + +rbx-head + +String#downcase == vs. String#casecmp +Rehearsal ---------------------------------------------------- +String#downcase1 0.702746 0.005229 0.707975 ( 0.621969) +String#downcase2 0.701429 0.001617 0.703046 ( 0.691833) +String#downcase3 1.042835 0.002952 1.045787 ( 0.953992) +casecmp1 0.654571 0.002239 0.656810 ( 0.480158) +casecmp1-1 0.484706 0.001105 0.485811 ( 0.398601) +casecmp2 0.564140 0.001579 0.565719 ( 0.545332) +casecmp2-1 0.554889 0.001153 0.556042 ( 0.539569) +------------------------------------------- total: 4.721190sec + + user system total real +String#downcase1 0.491199 0.001081 0.492280 ( 0.493727) +String#downcase2 0.631059 0.001018 0.632077 ( 0.629885) +String#downcase3 0.968867 0.002504 0.971371 ( 0.976734) +casecmp1 0.364496 0.000434 0.364930 ( 0.365262) +casecmp1-1 0.373140 0.000562 0.373702 ( 0.374136) +casecmp2 0.487644 0.001057 0.488701 ( 0.490302) +casecmp2-1 0.469868 0.001178 0.471046 ( 0.472220) + +ruby-1.8.7-p330 + +String#downcase == vs. String#casecmp +Rehearsal ---------------------------------------------------- +String#downcase1 0.780000 0.000000 0.780000 ( 0.783979) +String#downcase2 0.950000 0.000000 0.950000 ( 0.954109) +String#downcase3 0.960000 0.000000 0.960000 ( 0.960554) +casecmp1 0.440000 0.000000 0.440000 ( 0.442546) +casecmp1-1 0.490000 0.000000 0.490000 ( 0.487795) +casecmp2 0.530000 0.000000 0.530000 ( 0.535819) +casecmp2-1 0.570000 0.000000 0.570000 ( 0.574653) +------------------------------------------- total: 4.720000sec + + user system total real +String#downcase1 0.780000 0.000000 0.780000 ( 0.780692) +String#downcase2 0.980000 0.010000 0.990000 ( 0.982925) +String#downcase3 0.960000 0.000000 0.960000 ( 0.961501) +casecmp1 0.440000 0.000000 0.440000 ( 0.444528) +casecmp1-1 0.490000 0.000000 0.490000 ( 0.487437) +casecmp2 0.540000 0.000000 0.540000 ( 0.537686) +casecmp2-1 0.570000 0.000000 0.570000 ( 0.574253) + +ruby-1.9.2-p136 + +String#downcase == vs. String#casecmp +Rehearsal ---------------------------------------------------- +String#downcase1 0.750000 0.000000 0.750000 ( 0.750523) +String#downcase2 1.190000 0.000000 1.190000 ( 1.193346) +String#downcase3 1.030000 0.010000 1.040000 ( 1.036435) +casecmp1 0.640000 0.000000 0.640000 ( 0.640327) +casecmp1-1 0.480000 0.000000 0.480000 ( 0.484709) # With all this crap running, some flukes pop out +casecmp2 0.820000 0.000000 0.820000 ( 0.822223) +casecmp2-1 0.660000 0.000000 0.660000 ( 0.664190) +------------------------------------------- total: 5.580000sec + + user system total real +String#downcase1 0.760000 0.000000 0.760000 ( 0.759816) +String#downcase2 1.150000 0.010000 1.160000 ( 1.150792) +String#downcase3 1.000000 0.000000 1.000000 ( 1.005549) +casecmp1 0.650000 0.000000 0.650000 ( 0.644021) +casecmp1-1 0.490000 0.000000 0.490000 ( 0.494456) +casecmp2 0.820000 0.000000 0.820000 ( 0.817689) +casecmp2-1 0.680000 0.000000 0.680000 ( 0.685121) +=end diff --git a/lib/vendor/excon/benchmarks/excon.rb b/lib/vendor/excon/benchmarks/excon.rb new file mode 100644 index 0000000..5196730 --- /dev/null +++ b/lib/vendor/excon/benchmarks/excon.rb @@ -0,0 +1,69 @@ +require 'rubygems' if RUBY_VERSION < '1.9' +require 'bundler' + +Bundler.require(:default) +Bundler.require(:benchmark) + +require 'sinatra/base' + +require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon') + +module Excon + class Server < Sinatra::Base + + def self.run + Rack::Handler::WEBrick.run( + Excon::Server.new, + :Port => 9292, + :AccessLog => [], + :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR) + ) + end + + get '/data/:amount' do |amount| + 'x' * amount.to_i + end + + end +end + +def with_server(&block) + pid = Process.fork do + Excon::Server.run + end + loop do + sleep(1) + begin + Excon.get('http://localhost:9292/api/foo') + break + rescue + end + end + yield +ensure + Process.kill(9, pid) +end + +require 'tach' + +size = 10_000 +path = '/data/' << size.to_s +url = 'http://localhost:9292' << path + +times = 1_000 + +with_server do + + Tach.meter(times) do + + tach('Excon') do + Excon.get(url).body + end + + excon = Excon.new(url) + tach('Excon (persistent)') do + excon.request(:method => 'get').body + end + + end +end diff --git a/lib/vendor/excon/benchmarks/excon_vs.rb b/lib/vendor/excon/benchmarks/excon_vs.rb new file mode 100644 index 0000000..7d16969 --- /dev/null +++ b/lib/vendor/excon/benchmarks/excon_vs.rb @@ -0,0 +1,165 @@ +require 'rubygems' if RUBY_VERSION < '1.9' +require 'bundler' + +Bundler.require(:default) +Bundler.require(:benchmark) + +require 'sinatra/base' + +require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon') + +module Excon + class Server < Sinatra::Base + + def self.run + Rack::Handler::WEBrick.run( + Excon::Server.new, + :Port => 9292, + :AccessLog => [], + :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR) + ) + end + + get '/data/:amount' do |amount| + 'x' * amount.to_i + end + + end +end + +def with_server(&block) + pid = Process.fork do + Excon::Server.run + end + loop do + sleep(1) + begin + Excon.get('http://localhost:9292/api/foo') + break + rescue + end + end + yield +ensure + Process.kill(9, pid) +end + +require 'em-http-request' +require 'httparty' +require 'net/http' +require 'open-uri' +require 'rest_client' +require 'tach' +require 'typhoeus' + +size = 10_000 +path = '/data/' << size.to_s +url = 'http://localhost:9292' << path + +times = 1_000 + +with_server do + + Tach.meter(times) do + + tach('curb (persistent)') do |n| + curb = Curl::Easy.new + + n.times do + curb.url = url + curb.http_get + curb.body_str + end + end + + tach('em-http-request') do |n| + EventMachine.run { + count = 0 + + n.times do + http = EventMachine::HttpRequest.new(url).get + + http.callback { + http.response + count += 1 + EM.stop if count == n + } + + http.errback { + http.response + count += 1 + EM.stop if count == n + } + end + } + end + + tach('Excon') do + Excon.get(url).body + end + + excon = Excon.new(url) + tach('Excon (persistent)') do + excon.request(:method => 'get').body + end + + tach('HTTParty') do + HTTParty.get(url).body + end + + tach('Net::HTTP') do + # Net::HTTP.get('localhost', path, 9292) + Net::HTTP.start('localhost', 9292) {|http| http.get(path).body } + end + + Net::HTTP.start('localhost', 9292) do |http| + tach('Net::HTTP (persistent)') do + http.get(path).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 + + end +end + +# +--------------------------+----------+ +# | tach | total | +# +--------------------------+----------+ +# | Excon (persistent) | 1.529095 | +# +--------------------------+----------+ +# | curb (persistent) | 1.740387 | +# +--------------------------+----------+ +# | Typhoeus | 1.876236 | +# +--------------------------+----------+ +# | Excon | 2.001858 | +# +--------------------------+----------+ +# | StreamlyFFI (persistent) | 2.200701 | +# +--------------------------+----------+ +# | Net::HTTP | 2.395704 | +# +--------------------------+----------+ +# | Net::HTTP (persistent) | 2.418099 | +# +--------------------------+----------+ +# | HTTParty | 2.659317 | +# +--------------------------+----------+ +# | RestClient | 2.958159 | +# +--------------------------+----------+ +# | open-uri | 2.987051 | +# +--------------------------+----------+ +# | em-http-request | 4.123798 | +# +--------------------------+----------+ diff --git a/lib/vendor/excon/benchmarks/for_vs_array_each.rb b/lib/vendor/excon/benchmarks/for_vs_array_each.rb new file mode 100644 index 0000000..b88f449 --- /dev/null +++ b/lib/vendor/excon/benchmarks/for_vs_array_each.rb @@ -0,0 +1,27 @@ +require 'rubygems' +require 'tach' + +data = ["some", "var", "goes", "in", :here, 0] +Tach.meter(1_000_000) do + tach('for') do + for element in data + element == nil + end + end + tach('each') do + data.each do |element| + element == nil + end + end +end + +# ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] +# +# +------+----------+ +# | tach | total | +# +------+----------+ +# | for | 2.958672 | +# +------+----------+ +# | each | 2.983550 | +# +------+----------+ +# diff --git a/lib/vendor/excon/benchmarks/for_vs_hash_each.rb b/lib/vendor/excon/benchmarks/for_vs_hash_each.rb new file mode 100644 index 0000000..c4db5ef --- /dev/null +++ b/lib/vendor/excon/benchmarks/for_vs_hash_each.rb @@ -0,0 +1,27 @@ +require 'rubygems' +require 'tach' + +data = {"some" => "var", "goes" => "in", :here => 0} +Tach.meter(1_000_000) do + tach('for') do + for key, values in data + key == values + end + end + tach('each') do + data.each do |key, values| + key == values + end + end +end + +# ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] +# +# +------+----------+ +# | tach | total | +# +------+----------+ +# | each | 2.748909 | +# +------+----------+ +# | for | 2.949512 | +# +------+----------+ +# diff --git a/lib/vendor/excon/benchmarks/has_key-vs-lookup.rb b/lib/vendor/excon/benchmarks/has_key-vs-lookup.rb new file mode 100644 index 0000000..b617c0c --- /dev/null +++ b/lib/vendor/excon/benchmarks/has_key-vs-lookup.rb @@ -0,0 +1,177 @@ +# Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell + +require 'benchmark' + +iters = 1000000 +hash = { + 'some_key' => 'some_val', + 'nil_key' => nil +} + +puts 'Hash#has_key vs. Hash#[]' +Benchmark.bmbm do |x| + x.report('Hash#has_key') do + iters.times.each do + hash.has_key? 'some_key' + end + end + + x.report('Hash#has_key (if statement)') do + iters.times.each do + if hash.has_key?('other_key') + "hooray!" + end + end + end + + x.report('Hash#has_key (non-existant)') do + iters.times.each do + hash.has_key? 'other_key' + end + end + + x.report('Hash#[]') do + iters.times.each do + hash['some_key'] + end + end + + x.report('Hash#[] (if statement)') do + iters.times.each do + if hash['some_key'] + "hooray!" + end + end + end + + x.report('Hash#[] (non-existant)') do + iters.times.each do + hash['other_key'] + end + end + + x.report('Hash#has_key (if statement) explicit nil check') do + iters.times.each do + if hash.has_key?('nil_key') && !hash['nil_key'].nil? + "hooray!" + end + end + end + + + x.report('Hash#has_key (if statement) implicit nil check') do + iters.times.each do + if hash.has_key?('nil_key') && hash['nil_key'] + "hooray!" + end + end + end + + x.report('Hash#[] (if statement with nil)') do + iters.times.each do + if hash['nil_key'] + "hooray!" + end + end + end +end + +=begin + +$ rvm exec bash -c 'echo $RUBY_VERSION && ruby has_key-vs-hash\[key\].rb' + +jruby-1.5.6 +Hash#has_key vs. Hash#[] +Rehearsal --------------------------------------------------------------- +Hash#has_key 0.410000 0.000000 0.410000 ( 0.341000) +Hash#has_key (if statement) 0.145000 0.000000 0.145000 ( 0.145000) +Hash#has_key (non-existant) 0.116000 0.000000 0.116000 ( 0.116000) +Hash#[] 0.189000 0.000000 0.189000 ( 0.189000) +Hash#[] (if statement) 0.176000 0.000000 0.176000 ( 0.176000) +Hash#[] (non-existant) 0.302000 0.000000 0.302000 ( 0.302000) +------------------------------------------------------ total: 1.338000sec + + user system total real +Hash#has_key 0.128000 0.000000 0.128000 ( 0.128000) +Hash#has_key (if statement) 0.128000 0.000000 0.128000 ( 0.128000) +Hash#has_key (non-existant) 0.153000 0.000000 0.153000 ( 0.153000) +Hash#[] 0.206000 0.000000 0.206000 ( 0.206000) +Hash#[] (if statement) 0.182000 0.000000 0.182000 ( 0.182000) +Hash#[] (non-existant) 0.252000 0.000000 0.252000 ( 0.252000) + +macruby-0.7.1 +Hash#has_key vs. Hash#[] +Rehearsal --------------------------------------------------------------- +Hash#has_key 2.530000 0.050000 2.580000 ( 1.917643) +Hash#has_key (if statement) 2.590000 0.050000 2.640000 ( 1.935221) +Hash#has_key (non-existant) 2.580000 0.050000 2.630000 ( 1.964230) +Hash#[] 2.240000 0.040000 2.280000 ( 1.640999) +Hash#[] (if statement) 3.620000 0.070000 3.690000 ( 2.530248) +Hash#[] (non-existant) 2.060000 0.040000 2.100000 ( 1.473487) +----------------------------------------------------- total: 15.920000sec + + user system total real +Hash#has_key 2.230000 0.030000 2.260000 ( 1.661843) +Hash#has_key (if statement) 2.180000 0.040000 2.220000 ( 1.605644) +Hash#has_key (non-existant) 2.160000 0.040000 2.200000 ( 1.582561) +Hash#[] 2.160000 0.030000 2.190000 ( 1.581448) +Hash#[] (if statement) 3.440000 0.070000 3.510000 ( 2.393421) +Hash#[] (non-existant) 2.330000 0.040000 2.370000 ( 1.699338) + +rbx-head +Hash#has_key vs. Hash#[] +Rehearsal --------------------------------------------------------------- +Hash#has_key 0.660584 0.004932 0.665516 ( 0.508601) +Hash#has_key (if statement) 0.261708 0.000532 0.262240 ( 0.263021) +Hash#has_key (non-existant) 0.265908 0.000827 0.266735 ( 0.259509) +Hash#[] 0.396607 0.001189 0.397796 ( 0.372997) +Hash#[] (if statement) 0.553003 0.001589 0.554592 ( 0.543859) +Hash#[] (non-existant) 0.323748 0.000884 0.324632 ( 0.319055) +------------------------------------------------------ total: 2.471511sec + + user system total real +Hash#has_key 0.332239 0.000819 0.333058 ( 0.333809) +Hash#has_key (if statement) 0.284344 0.000521 0.284865 ( 0.285330) +Hash#has_key (non-existant) 0.339695 0.001301 0.340996 ( 0.324259) +Hash#[] 0.298555 0.000368 0.298923 ( 0.299557) +Hash#[] (if statement) 0.392755 0.000773 0.393528 ( 0.395473) +Hash#[] (non-existant) 0.277721 0.000464 0.278185 ( 0.278540) + +ruby-1.8.7-p330 +Hash#has_key vs. Hash#[] +Rehearsal --------------------------------------------------------------- +Hash#has_key 0.450000 0.000000 0.450000 ( 0.450143) +Hash#has_key (if statement) 0.440000 0.000000 0.440000 ( 0.448278) +Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.416959) +Hash#[] 0.450000 0.000000 0.450000 ( 0.450727) +Hash#[] (if statement) 0.550000 0.000000 0.550000 ( 0.555043) +Hash#[] (non-existant) 0.530000 0.000000 0.530000 ( 0.527189) +------------------------------------------------------ total: 2.840000sec + + user system total real +Hash#has_key 0.440000 0.000000 0.440000 ( 0.447746) +Hash#has_key (if statement) 0.450000 0.000000 0.450000 ( 0.450331) +Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.419157) +Hash#[] 0.450000 0.000000 0.450000 ( 0.454438) +Hash#[] (if statement) 0.570000 0.000000 0.570000 ( 0.563948) +Hash#[] (non-existant) 0.520000 0.000000 0.520000 ( 0.527866) + +ruby-1.9.2-p136 +Hash#has_key vs. Hash#[] +Rehearsal --------------------------------------------------------------- +Hash#has_key 0.690000 0.000000 0.690000 ( 0.691657) +Hash#has_key (if statement) 0.630000 0.000000 0.630000 ( 0.638418) +Hash#has_key (non-existant) 0.640000 0.000000 0.640000 ( 0.637510) +Hash#[] 0.580000 0.000000 0.580000 ( 0.584500) +Hash#[] (if statement) 0.840000 0.010000 0.850000 ( 0.837541) +Hash#[] (non-existant) 0.810000 0.000000 0.810000 ( 0.811598) +------------------------------------------------------ total: 4.200000sec + + user system total real +Hash#has_key 0.690000 0.000000 0.690000 ( 0.694192) +Hash#has_key (if statement) 0.640000 0.000000 0.640000 ( 0.641729) +Hash#has_key (non-existant) 0.630000 0.000000 0.630000 ( 0.634470) +Hash#[] 0.580000 0.000000 0.580000 ( 0.587844) +Hash#[] (if statement) 0.830000 0.000000 0.830000 ( 0.832323) +Hash#[] (non-existant) 0.790000 0.010000 0.800000 ( 0.791689) +=end diff --git a/lib/vendor/excon/benchmarks/headers_case_sensitivity.rb b/lib/vendor/excon/benchmarks/headers_case_sensitivity.rb new file mode 100644 index 0000000..85aa513 --- /dev/null +++ b/lib/vendor/excon/benchmarks/headers_case_sensitivity.rb @@ -0,0 +1,83 @@ +require 'rubygems' +require 'stringio' +require 'tach' + +def all_match_socket + io = StringIO.new + io << "Connection: close\n" + io << "Content-Length: 000\n" + io << "Content-Type: text/html\n" + io << "Date: Xxx, 00 Xxx 0000 00:00:00 GMT\n" + io << "Server: xxx\n" + io << "Transfer-Encoding: chunked\n" + io << "\n\n" + io.rewind + io +end + +Formatador.display_line('all_match') +Formatador.indent do + Tach.meter(10_000) do + tach('compare on read') do + socket, headers = all_match_socket, {} + until ((data = socket.readline).chop!).empty? + key, value = data.split(': ') + headers[key] = value + (key.casecmp('Transfer-Encoding') == 0) && (value.casecmp('chunked') == 0) + (key.casecmp('Connection') == 0) && (value.casecmp('close') == 0) + (key.casecmp('Content-Length') == 0) + end + end + + tach('original') do + socket, headers = all_match_socket, {} + until ((data = socket.readline).chop!).empty? + key, value = data.split(': ') + headers[key] = value + end + headers.has_key?('Transfer-Encoding') && headers['Transfer-Encoding'].casecmp('chunked') == 0 + headers.has_key?('Connection') && headers['Connection'].casecmp('close') == 0 + headers.has_key?('Content-Length') + end + end +end + +def none_match_socket + io = StringIO.new + io << "Cache-Control: max-age=0\n" + io << "Content-Type: text/html\n" + io << "Date: Xxx, 00 Xxx 0000 00:00:00 GMT\n" + io << "Expires: Xxx, 00 Xxx 0000 00:00:00 GMT\n" + io << "Last-Modified: Xxx, 00 Xxx 0000 00:00:00 GMT\n" + io << "Server: xxx\n" + io << "\n\n" + io.rewind + io +end + +Formatador.display_line('none_match') +Formatador.indent do + Tach.meter(10_000) do + tach('compare on read') do + socket, headers = none_match_socket, {} + until ((data = socket.readline).chop!).empty? + key, value = data.split(': ') + headers[key] = value + (key.casecmp('Transfer-Encoding') == 0) && (value.casecmp('chunked') == 0) + (key.casecmp('Connection') == 0) && (value.casecmp('close') == 0) + (key.casecmp('Content-Length') == 0) + end + end + + tach('original') do + socket, headers = none_match_socket, {} + until ((data = socket.readline).chop!).empty? + key, value = data.split(': ') + headers[key] = value + end + headers.has_key?('Transfer-Encoding') && headers['Transfer-Encoding'].casecmp('chunked') == 0 + headers.has_key?('Connection') && headers['Connection'].casecmp('close') == 0 + headers.has_key?('Content-Length') + end + end +end
\ No newline at end of file diff --git a/lib/vendor/excon/benchmarks/headers_split_vs_match.rb b/lib/vendor/excon/benchmarks/headers_split_vs_match.rb new file mode 100644 index 0000000..276c366 --- /dev/null +++ b/lib/vendor/excon/benchmarks/headers_split_vs_match.rb @@ -0,0 +1,34 @@ +require 'rubygems' +require 'tach' + +data = "Content-Length: 100" +Tach.meter(1_000_000) do + tach('regex') do + data.match(/(.*):\s(.*)/) + header = [$1, $2] + end + tach('split') do + header = data.split(': ', 2) + end + tach('split regex') do + header = data.split(/:\s*/, 2) + end +end + +# +-------------+----------+ +# | tach | total | +# +-------------+----------+ +# | split regex | 5.940233 | +# +-------------+----------+ +# | split | 7.327549 | +# +-------------+----------+ +# | regex | 8.736390 | +# +-------------+----------+ + +# +-------+----------+----------+ +# | tach | average | total | +# +-------+----------+----------+ +# | regex | 4.680451 | 4.680451 | +# +-------+----------+----------+ +# | split | 4.393218 | 4.393218 | +# +-------+----------+----------+ diff --git a/lib/vendor/excon/benchmarks/implicit_block-vs-explicit_block.rb b/lib/vendor/excon/benchmarks/implicit_block-vs-explicit_block.rb new file mode 100644 index 0000000..7337b4e --- /dev/null +++ b/lib/vendor/excon/benchmarks/implicit_block-vs-explicit_block.rb @@ -0,0 +1,98 @@ +# Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell + +require 'benchmark' + +iters = 1000000 + +def do_explicit(&block) + var = "hello" + block.call(var) +end + +def do_implicit + var = "hello" + yield(var) +end + +puts 'explicit block vs implicit' +Benchmark.bmbm do |x| + x.report('explicit') do + iters.times.each do + do_explicit {|var| + var << "goodbye" + } + end + end + + x.report('implicit') do + iters.times.each do + do_implicit {|var| + var << "goodbye" + } + end + end +end + +=begin +rvm exec bash -c 'echo && echo $RUBY_VERSION && echo && ruby implicit_block-vs-explicit_block.rb' + +jruby-1.5.6 + +explicit block vs implicit +Rehearsal -------------------------------------------- +explicit 1.163000 0.000000 1.163000 ( 1.106000) +implicit 0.499000 0.000000 0.499000 ( 0.499000) +----------------------------------- total: 1.662000sec + + user system total real +explicit 0.730000 0.000000 0.730000 ( 0.730000) +implicit 0.453000 0.000000 0.453000 ( 0.453000) + +macruby-0.7.1 + +explicit block vs implicit +Rehearsal -------------------------------------------- +explicit 5.070000 0.130000 5.200000 ( 3.546388) +implicit 3.140000 0.050000 3.190000 ( 2.255986) +----------------------------------- total: 8.390000sec + + user system total real +explicit 5.340000 0.140000 5.480000 ( 3.774963) +implicit 3.170000 0.060000 3.230000 ( 2.279951) + +rbx-head + +explicit block vs implicit +Rehearsal -------------------------------------------- +explicit 1.270136 0.006507 1.276643 ( 1.181588) +implicit 0.839831 0.002203 0.842034 ( 0.820849) +----------------------------------- total: 2.118677sec + + user system total real +explicit 0.960593 0.001526 0.962119 ( 0.966404) +implicit 0.700361 0.001126 0.701487 ( 0.703591) + +ruby-1.8.7-p330 + +explicit block vs implicit +Rehearsal -------------------------------------------- +explicit 3.970000 0.000000 3.970000 ( 3.985157) +implicit 1.560000 0.000000 1.560000 ( 1.567599) +----------------------------------- total: 5.530000sec + + user system total real +explicit 3.990000 0.010000 4.000000 ( 4.002637) +implicit 1.560000 0.000000 1.560000 ( 1.560901) + +ruby-1.9.2-p136 + +explicit block vs implicit +Rehearsal -------------------------------------------- +explicit 2.620000 0.010000 2.630000 ( 2.633762) +implicit 1.080000 0.000000 1.080000 ( 1.076809) +----------------------------------- total: 3.710000sec + + user system total real +explicit 2.630000 0.010000 2.640000 ( 2.637658) +implicit 1.070000 0.000000 1.070000 ( 1.073589) +=end diff --git a/lib/vendor/excon/benchmarks/merging.rb b/lib/vendor/excon/benchmarks/merging.rb new file mode 100644 index 0000000..7674e3f --- /dev/null +++ b/lib/vendor/excon/benchmarks/merging.rb @@ -0,0 +1,21 @@ +require 'rubygems' +require 'tach' + +Tach.meter(10_000) do + + tach('merge') do + default = { :a => 1, :b => 2 } + override = { :b => 3, :c => 4 } + override = default.merge(override) + end + + tach('loop') do + default = { :a => 1, :b => 2 } + override = { :b => 3, :c => 4 } + for key, value in default + override[key] ||= default[key] + end + override + end + +end diff --git a/lib/vendor/excon/benchmarks/single_vs_double_quotes.rb b/lib/vendor/excon/benchmarks/single_vs_double_quotes.rb new file mode 100644 index 0000000..aac3342 --- /dev/null +++ b/lib/vendor/excon/benchmarks/single_vs_double_quotes.rb @@ -0,0 +1,21 @@ +require 'rubygems' +require 'tach' + +Tach.meter(1_000_000) do + tach('double') do + "path" + end + tach('single') do + 'path' + end +end + +# [double, single] +# +# +--------+----------+ +# | tach | total | +# +--------+----------+ +# | single | 0.416340 | +# +--------+----------+ +# | double | 0.416570 | +# +--------+----------+ diff --git a/lib/vendor/excon/benchmarks/string_ranged_index.rb b/lib/vendor/excon/benchmarks/string_ranged_index.rb new file mode 100644 index 0000000..68c2fdc --- /dev/null +++ b/lib/vendor/excon/benchmarks/string_ranged_index.rb @@ -0,0 +1,87 @@ +# Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell + +require 'benchmark' + +iters = 1000000 + +string = "Test String OMG" + +puts 'String ranged index vs. "coordinates"' +Benchmark.bmbm do |x| + x.report('ranged index') do + iters.times.each do + text = string[2..9] + end + end + + x.report('coordinates') do + iters.times.each do + text = string[2, 9] + end + end +end + +=begin +rvm exec bash -c 'echo && echo $RUBY_VERSION && echo && ruby string_ranged_index.rb' + + +jruby-1.5.6 + +String ranged index vs. "coordinates" +Rehearsal ------------------------------------------------ +ranged index 0.419000 0.000000 0.419000 ( 0.372000) +coordinates 0.167000 0.000000 0.167000 ( 0.167000) +--------------------------------------- total: 0.586000sec + + user system total real +ranged index 0.158000 0.000000 0.158000 ( 0.159000) +coordinates 0.125000 0.000000 0.125000 ( 0.125000) + +macruby-0.7.1 + +String ranged index vs. "coordinates" +Rehearsal ------------------------------------------------ +ranged index 1.490000 0.030000 1.520000 ( 1.061326) +coordinates 1.410000 0.030000 1.440000 ( 0.973640) +--------------------------------------- total: 2.960000sec + + user system total real +ranged index 1.520000 0.030000 1.550000 ( 1.081424) +coordinates 1.480000 0.030000 1.510000 ( 1.029214) + +rbx-head + +String ranged index vs. "coordinates" +Rehearsal ------------------------------------------------ +ranged index 1.333304 0.009398 1.342702 ( 1.229629) +coordinates 0.306087 0.000603 0.306690 ( 0.303538) +--------------------------------------- total: 1.649392sec + + user system total real +ranged index 0.923626 0.001597 0.925223 ( 0.927411) +coordinates 0.298910 0.000533 0.299443 ( 0.300255) + +ruby-1.8.7-p330 + +String ranged index vs. "coordinates" +Rehearsal ------------------------------------------------ +ranged index 0.730000 0.000000 0.730000 ( 0.738612) +coordinates 0.660000 0.000000 0.660000 ( 0.660689) +--------------------------------------- total: 1.390000sec + + user system total real +ranged index 0.750000 0.000000 0.750000 ( 0.746172) +coordinates 0.640000 0.000000 0.640000 ( 0.640687) + +ruby-1.9.2-p136 + +String ranged index vs. "coordinates" +Rehearsal ------------------------------------------------ +ranged index 0.670000 0.000000 0.670000 ( 0.679046) +coordinates 0.620000 0.000000 0.620000 ( 0.622257) +--------------------------------------- total: 1.290000sec + + user system total real +ranged index 0.680000 0.000000 0.680000 ( 0.686510) +coordinates 0.620000 0.000000 0.620000 ( 0.624269) +=end diff --git a/lib/vendor/excon/benchmarks/strip_newline.rb b/lib/vendor/excon/benchmarks/strip_newline.rb new file mode 100644 index 0000000..88a964f --- /dev/null +++ b/lib/vendor/excon/benchmarks/strip_newline.rb @@ -0,0 +1,115 @@ +# require 'benchmark' +# +# COUNT = 1_000_000 +# data = "Content-Length: 100\r\n" +# Benchmark.bmbm(25) do |bench| +# bench.report('chomp') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.chomp +# end +# end +# bench.report('chomp!') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.chomp! +# end +# end +# bench.report('chop') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.chop +# end +# end +# bench.report('chop!') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.chop! +# end +# end +# bench.report('strip') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.strip +# end +# end +# bench.report('strip!') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data.strip! +# end +# end +# bench.report('index') do +# COUNT.times do +# data = "Content-Length: 100\r\n" +# data[0..-3] +# end +# end +# end + + + +# Rehearsal ------------------------------------------------------------ +# chomp 0.640000 0.000000 0.640000 ( 0.644043) +# chomp! 0.530000 0.000000 0.530000 ( 0.531415) +# chop 0.620000 0.000000 0.620000 ( 0.624321) +# chop! 0.500000 0.000000 0.500000 ( 0.509146) +# strip 0.640000 0.000000 0.640000 ( 0.638785) +# strip! 0.530000 0.000000 0.530000 ( 0.532196) +# index 0.740000 0.000000 0.740000 ( 0.745742) +# --------------------------------------------------- total: 4.200000sec +# +# user system total real +# chomp 0.640000 0.010000 0.650000 ( 0.647287) +# chomp! 0.530000 0.000000 0.530000 ( 0.532868) +# chop 0.630000 0.000000 0.630000 ( 0.628236) +# chop! 0.520000 0.000000 0.520000 ( 0.522950) +# strip 0.640000 0.000000 0.640000 ( 0.646328) +# strip! 0.520000 0.000000 0.520000 ( 0.532715) +# index 0.740000 0.010000 0.750000 ( 0.771277) + +require 'rubygems' +require 'tach' + +data = "Content-Length: 100\r\n" +Tach.meter(1_000_000) do + tach('chomp') do + data.dup.chomp + end + tach('chomp!') do + data.dup.chomp! + end + tach('chop') do + data.dup.chop + end + tach('chop!') do + data.dup.chop! + end + tach('strip') do + data.dup.strip + end + tach('strip!') do + data.dup.strip! + end + tach('index') do + data.dup[0..-3] + end +end + +# +--------+----------+----------+ +# | tach | average | total | +# +--------+----------+----------+ +# | chomp | 1.444547 | 1.444547 | +# +--------+----------+----------+ +# | chomp! | 1.276813 | 1.276813 | +# +--------+----------+----------+ +# | chop | 1.422744 | 1.422744 | +# +--------+----------+----------+ +# | chop! | 1.240941 | 1.240941 | +# +--------+----------+----------+ +# | strip | 1.444776 | 1.444776 | +# +--------+----------+----------+ +# | strip! | 1.266459 | 1.266459 | +# +--------+----------+----------+ +# | index | 1.557975 | 1.557975 | +# +--------+----------+----------+
\ No newline at end of file diff --git a/lib/vendor/excon/benchmarks/vs_stdlib.rb b/lib/vendor/excon/benchmarks/vs_stdlib.rb new file mode 100644 index 0000000..fca9a1e --- /dev/null +++ b/lib/vendor/excon/benchmarks/vs_stdlib.rb @@ -0,0 +1,82 @@ +require 'rubygems' if RUBY_VERSION < '1.9' + +require 'sinatra/base' +require 'tach' + +require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon') + +module Excon + class Server < Sinatra::Base + + def self.run + Rack::Handler::WEBrick.run( + Excon::Server.new, + :Port => 9292, + :AccessLog => [], + :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR) + ) + end + + get '/data/:amount' do |amount| + 'x' * amount.to_i + end + + end +end + +def with_server(&block) + pid = Process.fork do + Excon::Server.run + end + loop do + sleep(1) + begin + Excon.get('http://localhost:9292/api/foo') + break + rescue + end + end + yield +ensure + Process.kill(9, pid) +end + +require 'net/http' +require 'open-uri' + +url = 'http://localhost:9292/data/1000' + +with_server do + + Tach.meter(100) do + + tach('Excon') do + Excon.get(url).body + end + +# tach('Excon (persistent)') do |times| +# excon = Excon.new(url) +# times.times do +# excon.request(:method => 'get').body +# end +# end + + tach('Net::HTTP') do + # Net::HTTP.get('localhost', '/data/1000', 9292) + Net::HTTP.start('localhost', 9292) {|http| http.get('/data/1000').body } + end + +# tach('Net::HTTP (persistent)') do |times| +# Net::HTTP.start('localhost', 9292) do |http| +# times.times do +# http.get('/data/1000').body +# end +# end +# end + +# tach('open-uri') do +# open(url).read +# end + + end +end |