1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
$: << './benchmarks'
require 'server'
url = 'http://127.0.0.1/10k.html'
with_server do
Tach.meter(100) do
excon = Excon.new(url)
tach('Excon (persistent)') do
excon.request(:method => 'get').body
end
tach('Excon') do
Excon.get(url).body
end
tach('em-http-request') do |n|
EventMachine.run {
count = 0
error = 0
n.times do
EM.next_tick do
http = EventMachine::HttpRequest.new(url, :connect_timeout => 1).get
http.callback {
count += 1
if count == n
p [count, error]
EM.stop
end
}
http.errback {
count += 1
error += 1
if count == n
p [count, error]
EM.stop
end
}
end
end
}
end
tach('em-http-request (persistent)') do |n|
EventMachine.run {
count = 0
error = 0
conn = EventMachine::HttpRequest.new(url)
n.times do
http = conn.get :keepalive => true
http.callback {
count += 1
if count == n
p [count, error]
EM.stop
end
}
http.errback {
count += 1
error += 1
if count == n
p [count, error]
EM.stop
end
}
end
}
end
end
end
# +------------------------------+----------+
# | tach | total |
# +------------------------------+----------+
# | em-http-request (persistent) | 0.018133 |
# +------------------------------+----------+
# | Excon (persistent) | 0.023975 |
# +------------------------------+----------+
# | Excon | 0.032877 |
# +------------------------------+----------+
# | em-http-request | 0.042891 |
# +------------------------------+----------+
|