Class: Tryouts::Drill::Sergeant::Benchmark
- Inherits:
-
Object
- Object
- Tryouts::Drill::Sergeant::Benchmark
- Defined in:
- lib/tryouts/drill/sergeant/benchmark.rb
Overview
Benchmark
The sergeant responsible for running benchmarks
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(reps = nil) ⇒ Benchmark
constructor
-
reps
Number of times to execute drill (>= 0, <= 1000000).
-
- #run(block, context, &inline) ⇒ Object
Constructor Details
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/tryouts/drill/sergeant/benchmark.rb', line 14 def output @output end |
Instance Method Details
#run(block, context, &inline) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tryouts/drill/sergeant/benchmark.rb', line 23 def run(block, context, &inline) # A Proc object takes precedence over an inline block. runtime = (block.nil? ? inline : block) response = Tryouts::Drill::Reality.new if runtime.nil? raise "We need a block to benchmark" else begin @reps.times do run = ::Benchmark.realtime { context.instance_eval &runtime } @stats.sample run end # We add the output after we run the block so that # that it'll remain nil if an exception was raised response.output = @stats rescue => e puts e., e.backtrace if Tryouts.verbose > 2 response.etype = e.class response.error = e. response.trace = e.backtrace end end response end |