Class: BigO::TimeComplexity
- Inherits:
-
Object
- Object
- BigO::TimeComplexity
- Includes:
- ComplexityBase
- Defined in:
- lib/big-o/time_complexity.rb
Overview
Measure time complexity.
Instance Attribute Summary
Attributes included from ComplexityBase
#options, #result, #result_set, #scale
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TimeComplexity
constructor
Raises the error percentage due to possible concurrency issue on the system (which in certain cases may cause some measures to be far longer than others).
-
#measure(*args) { ... } ⇒ Float
Measures the execution time that
fn
is using. -
#process ⇒ Object
Checks if the function can be measured and throw an error if it could not.
Methods included from ComplexityBase
#examine_result_set, #get_scale, #run_simulation
Constructor Details
#initialize(options = {}) ⇒ TimeComplexity
Raises the error percentage due to possible concurrency issue on the system (which in certain cases may cause some measures to be far longer than others).
8 9 10 11 |
# File 'lib/big-o/time_complexity.rb', line 8 def initialize( = {}) = { :error_pct => 0.1 }.merge() super() end |
Instance Method Details
#measure(*args) { ... } ⇒ Float
Measures the execution time that fn
is using.
25 26 27 28 29 30 |
# File 'lib/big-o/time_complexity.rb', line 25 def measure(*args, &b) t0 = Process.times b.call(*args) t1 = Process.times t1.utime - t0.utime end |
#process ⇒ Object
Checks if the function can be measured and throw an error if it could not.
14 15 16 17 18 |
# File 'lib/big-o/time_complexity.rb', line 14 def process @scale ||= get_scale raise InstantaneousExecutionError.new unless @scale > 0 super end |