Class: Spec::Performance::Example::PerformanceExecutionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/performance/example/performance_execution_builder.rb

Defined Under Namespace

Modules: PerformanceHelpers

Constant Summary collapse

EXAMPLE_RUN_TIME_LABEL =
"Performance Example Run Time"
ITERATION_RUN_TIME_LABEL =
"Performance Iteration Run Time"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &implementation) ⇒ PerformanceExecutionBuilder

Returns a new instance of PerformanceExecutionBuilder.



11
12
13
14
# File 'lib/spec/performance/example/performance_execution_builder.rb', line 11

def initialize(options, &implementation)
  @options = options
  @impl = implementation
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/spec/performance/example/performance_execution_builder.rb', line 6

def options
  @options
end

Instance Method Details

#performance_procObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/spec/performance/example/performance_execution_builder.rb', line 16

def performance_proc
  iterations_per_slice = options[:iterations] / options[:concurrency]

  # NOTE: Block execution only works if this is a local variable.
  implementation = @impl

  Proc.new do
    extend(PerformanceHelpers)

    example_run_time, maximum_iteration_time = _run_performance_loop(iterations_per_slice, &implementation)
    _assert_iterations_per_second(example_run_time, iterations_per_slice, options[:iterations_per_second]) if options[:iterations_per_second]
    _assert_maximum_iteration_time(maximum_iteration_time, options[:maximum_iteration_time]) if options[:maximum_iteration_time]
  end
end