Module: CSVPlusPlus::BenchmarkedCompiler

Defined in:
lib/csv_plus_plus/benchmarked_compiler.rb

Overview

Extend a Compiler class and add benchmark timings

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#benchmarkObject

Returns the value of attribute benchmark.



10
11
12
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 10

def benchmark
  @benchmark
end

#timingsObject (readonly)

Returns the value of attribute timings.



10
11
12
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 10

def timings
  @timings
end

Class Method Details

.with_benchmarks(compiler, &block) ⇒ Object

Wrap a Compiler with our instance methods that add benchmarks



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 13

def self.with_benchmarks(compiler, &block)
  ::Benchmark.benchmark(::Benchmark::CAPTION, 25, ::Benchmark::FORMAT, '> Total') do |x|
    # compiler = new(options:, runtime:, benchmark: x)
    compiler.extend(self)
    compiler.benchmark = x

    block.call(compiler)

    [compiler.timings.reduce(:+)]
  end
end

Instance Method Details

#outputting!Object

Time the Compiler#outputting! stage



32
33
34
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 32

def outputting!
  time_stage('Writing the spreadsheet') { super }
end