Class: Benny::Executors::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/benny/executors/benchmark.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(benchmarks:, reporter:) ⇒ Benchmark

Returns a new instance of Benchmark.



10
11
12
13
# File 'lib/benny/executors/benchmark.rb', line 10

def initialize(benchmarks:, reporter:)
  @benchmarks = benchmarks
  @reporter   = reporter
end

Instance Attribute Details

#benchmarksObject (readonly)

Returns the value of attribute benchmarks.



8
9
10
# File 'lib/benny/executors/benchmark.rb', line 8

def benchmarks
  @benchmarks
end

#reporterObject (readonly)

Returns the value of attribute reporter.



8
9
10
# File 'lib/benny/executors/benchmark.rb', line 8

def reporter
  @reporter
end

Class Method Details

.execute(benchmarks:, reporter:) ⇒ Object



35
36
37
# File 'lib/benny/executors/benchmark.rb', line 35

def self.execute(benchmarks:, reporter:)
  new(benchmarks: benchmarks, reporter: reporter).execute
end

Instance Method Details

#executeObject



15
16
17
18
19
# File 'lib/benny/executors/benchmark.rb', line 15

def execute
  benchmarks.each do |benchmark|
    execute_one(benchmark)
  end
end

#execute_one(benchmark) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/benny/executors/benchmark.rb', line 21

def execute_one(benchmark)
  benchmark.definition.before_blocks.each(&:call)

  benchmark.definition.warmup_options.iterations.times do
    benchmark.block.call
  end

  measure = ::Benchmark.measure do
    benchmark.block.call
  end

  reporter.report(benchmark, measure)
end