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
|
# File 'lib/webmeter/benchmark.rb', line 3
def self.bench(params)
params[:paths] ||= Parser.new(params[:file]).parse || ["/"]
params[:workers] ||= 25
params[:address] ||= "example.com"
if params[:limit]
params[:paths] = params[:paths][0, params[:limit]]
end
workers = []
params[:workers].times { |w|
worker = Worker.new(params[:address], params[:paths])
worker.user_agent = w
workers << worker.run
}
start = Time.now
workers.each { |w| w.join }
time = (Time.now - start).to_f
requests = params[:paths].size * params[:workers]
puts "Webmeter #{params[:address]}"
puts "Time taken for test #{time}"
puts "Requests #{requests}"
puts "Req/sec #{requests/time}"
end
|