Class: Benchmark::HTTP::Statistics
- Defined in:
- lib/benchmark/http/statistics.rb
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Attributes inherited from Stopwatch
Instance Method Summary collapse
- #add(duration, result) ⇒ Object
- #failed ⇒ Object
-
#initialize ⇒ Statistics
constructor
A new instance of Statistics.
- #print(out = STDOUT) ⇒ Object
Methods inherited from Stopwatch
#average, #count, #duration, #latency, #measure, #per_second, #sample, #sequential_duration, #similar?, #standard_deviation, #standard_error, #to_json, #to_s, #valid?, #variance
Constructor Details
#initialize ⇒ Statistics
Returns a new instance of Statistics.
154 155 156 157 158 159 |
# File 'lib/benchmark/http/statistics.rb', line 154 def initialize(*) super # The count of the status codes seen in the responses: @responses = Hash.new{|h,k| 0} end |
Instance Attribute Details
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
161 162 163 |
# File 'lib/benchmark/http/statistics.rb', line 161 def responses @responses end |
Instance Method Details
#add(duration, result) ⇒ Object
167 168 169 170 171 |
# File 'lib/benchmark/http/statistics.rb', line 167 def add(duration, result) super @responses[result.status] += 1 end |
#failed ⇒ Object
163 164 165 |
# File 'lib/benchmark/http/statistics.rb', line 163 def failed @responses.sum{|status, count| status >= 400 ? count : 0} end |
#print(out = STDOUT) ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/benchmark/http/statistics.rb', line 173 def print(out = STDOUT) if valid? counts = @responses.sort.collect{|status, count| "#{count}x #{status}"}.join("; ") out.puts "#{@samples.size} samples: #{counts}. #{per_second.round(2)} requests per second. S/D: #{Seconds[standard_deviation]}." else out.puts "Not enough samples." end end |