-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.rb
30 lines (24 loc) · 1.28 KB
/
benchmark.rb
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
require 'benchmark/ips'
require_relative 'clients'
REPEAT_COUNT = (ENV['REPEAT_COUNT'] || 5).to_i
URL = (ENV['URL'] || 'http://google.com').freeze
URLS = ([URL] * REPEAT_COUNT).freeze
def run_test!(klass, urls)
result = klass.perform(urls)
return if result.size == urls.size
raise "Failed to run #{klass}"
end
Benchmark.ips do |x|
x.warmup = 0
x.report('Net::HTTP in sequence') { run_test!(Clients::NetHttp, URLS) }
x.report('Net::HTTP in threads') { run_test!(Clients::NetHttpThreads, URLS) }
x.report('Curb in threads') { run_test!(Clients::CurbThreads, URLS) }
x.report('Curb Multi') { run_test!(Clients::CurbMulti, URLS) }
x.report('Typhoeus Hydra') { run_test!(Clients::TyphoeusHydra, URLS) }
x.report('Patron with ConnectionPool') { run_test!(Clients::PatronWithConnectionPool, URLS) }
x.report('Parallel in threads') { run_test!(Clients::ParallelThreads, URLS) }
x.report('Celluloid futures') { run_test!(Clients::CelluloidFutures, URLS) }
x.report('EM-HTTP-request Multi') { run_test!(Clients::EmHttpRequestMulti, URLS) }
x.report('EM-HTTP-request with EM-Synchrony') { run_test!(Clients::EmHttpRequestSynchrony, URLS) }
x.compare!
end