Class: Dbtap::PerformsWithin
- Defined in:
- lib/dbtap/testers/performs_within.rb
Overview
Tests if a query performs within a certain period of time.
Each query is run ten times and
This is useful for benchmarking, and will verify that a query ran neither too slow nor too fast.
Instance Attribute Summary collapse
-
#delta ⇒ Object
readonly
Returns the value of attribute delta.
-
#expected_time ⇒ Object
readonly
Returns the value of attribute expected_time.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Attributes inherited from Tester
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(query, expected_time, delta, name = nil) ⇒ PerformsWithin
constructor
query- The query to benchmarkexpected_time- The average expected time to run the query once (in milliseconds)delta- The amount of time + or - that the query is allowed to deviate (in milliseconds)name- (optional) the name of the test. - #ok? ⇒ Boolean
Methods inherited from Tester
Constructor Details
#initialize(query, expected_time, delta, name = nil) ⇒ PerformsWithin
query - The query to benchmark expected_time - The average expected time to run the query once (in milliseconds) delta - The amount of time + or - that the query is allowed to deviate (in milliseconds) name - (optional) the name of the test
17 18 19 20 21 22 |
# File 'lib/dbtap/testers/performs_within.rb', line 17 def initialize(query, expected_time, delta, name = nil) @name = name @query = query @expected_time = expected_time @delta = delta end |
Instance Attribute Details
#delta ⇒ Object (readonly)
Returns the value of attribute delta.
12 13 14 |
# File 'lib/dbtap/testers/performs_within.rb', line 12 def delta @delta end |
#expected_time ⇒ Object (readonly)
Returns the value of attribute expected_time.
12 13 14 |
# File 'lib/dbtap/testers/performs_within.rb', line 12 def expected_time @expected_time end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
12 13 14 |
# File 'lib/dbtap/testers/performs_within.rb', line 12 def query @query end |
Instance Method Details
#errors ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dbtap/testers/performs_within.rb', line 28 def errors output = [] if time_diff < 0 output << "too slow by factor of #{time_factor}" else output << "too fast by factor of #{time_factor}" end output << "average runtime: #{elapsed_time} ms" output << "desired average: #{expected_time} +/- #{delta} ms" end |
#ok? ⇒ Boolean
24 25 26 |
# File 'lib/dbtap/testers/performs_within.rb', line 24 def ok? time_diff.abs.to_f <= delta end |