-
-
Save raggi/fd3b2570e41a2557e07f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ % ruby travis.rb | |
Rehearsal ---------------------------------------------------------------- | |
curl /repos/travis-ci/travis 0.000000 0.000000 0.020000 ( 0.890858) | |
em /repos/travis-ci/travis 0.010000 0.000000 0.010000 ( 0.449796) | |
typh /repos/travis-ci/travis 0.010000 0.000000 0.010000 ( 0.459140) | |
http /repos/travis-ci/travis 0.000000 0.000000 0.000000 ( 0.450288) | |
raws /repos/travis-ci/travis 0.010000 0.010000 0.020000 ( 0.427803) | |
------------------------------------------------------- total: 0.060000sec | |
user system total real | |
curl /repos/travis-ci/travis 0.000000 0.000000 0.010000 ( 0.456998) | |
em /repos/travis-ci/travis 0.000000 0.010000 0.010000 ( 0.415069) | |
typh /repos/travis-ci/travis 0.000000 0.000000 0.000000 ( 0.120468) | |
http /repos/travis-ci/travis 0.000000 0.000000 0.000000 ( 0.113598) | |
raws /repos/travis-ci/travis 0.010000 0.000000 0.010000 ( 0.428059) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http/persistent' | |
require 'em-http-request' | |
require 'typhoeus' | |
require 'benchmark' | |
api = URI("https://api.travis-ci.org") | |
Benchmark.bmbm(20) do |res| | |
res.report("curl /repos/travis-ci/travis") do | |
system "curl -s -q -o /dev/null https://api.travis-ci.org/repos/travis-ci/travis" | |
end | |
res.report("em /repos/travis-ci/travis") do | |
EM.run do | |
ehttp = EM::HttpRequest.new(api.to_s + "/repos/travis-ci/travis").get | |
ehttp.callback { EM.stop } | |
ehttp.errback { raise } | |
end | |
end | |
res.report("typh /repos/travis-ci/travis") do | |
Typhoeus.get("https://api.travis-ci.org/repos/travis-ci/travis") | |
end | |
res.report("http /repos/travis-ci/travis") do | |
http = Net::HTTP::Persistent.new | |
http.request(api, Net::HTTP::Get.new("/repos/travis-ci/travis")) | |
end | |
# N.B. This version is probably slow due to line oriented buffering, etc. | |
res.report("raws /repos/travis-ci/travis") do | |
sock = OpenSSL::SSL::SSLSocket.new(TCPSocket.new('api.travis-ci.org', 443)) | |
sock.connect | |
sock.write "GET /repos/travis-ci/travis HTTP/1.1\r\nHost: api.travis-ci.org\r\n\r\n" | |
cl = 0 | |
while line = sock.readline | |
if line =~ /^Content-Length: (\d+)\s*$/ | |
cl = $1.to_i | |
break | |
end | |
end | |
line = sock.readline until line == "\r\n" | |
sock.read cl | |
sock.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@i0rek huh? it's a 200 if you use https...