Class: CSVPlusPlus::BenchmarkedCompiler
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/benchmarked_compiler.rb
Overview
Extend a Compiler
class and add benchmark timings
Instance Attribute Summary collapse
-
#benchmark ⇒ Benchmark::Report
readonly
A
Benchmark
instance. -
#timings ⇒ Array<Benchmark::Tms>
readonly
Benchmark
timings that have been accumulated by each step of compilation.
Attributes inherited from Compiler
Class Method Summary collapse
-
.with_benchmarks(options:, runtime:, &block) ⇒ Object
Instantiate a
::Compiler
that can benchmark (time) it’s stages.
Instance Method Summary collapse
-
#initialize(benchmark:, options:, runtime:) ⇒ BenchmarkedCompiler
constructor
A new instance of BenchmarkedCompiler.
-
#outputting!(&block) ⇒ Object
Time the Compiler#outputting! stage rubocop:disable Naming/BlockForwarding.
Methods inherited from Compiler
#benchmark=, #compile_template, with_compiler
Constructor Details
#initialize(benchmark:, options:, runtime:) ⇒ BenchmarkedCompiler
Returns a new instance of BenchmarkedCompiler.
48 49 50 51 52 53 |
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 48 def initialize(benchmark:, options:, runtime:) super(options:, runtime:) @benchmark = ::T.let(benchmark, ::Benchmark::Report) @timings = ::T.let([], ::T::Array[::Benchmark::Tms]) end |
Instance Attribute Details
#benchmark ⇒ Benchmark::Report (readonly)
A Benchmark
instance
10 11 12 |
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 10 def benchmark @benchmark end |
#timings ⇒ Array<Benchmark::Tms> (readonly)
Benchmark
timings that have been accumulated by each step of compilation
10 11 12 |
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 10 def timings @timings end |
Class Method Details
.with_benchmarks(options:, runtime:, &block) ⇒ Object
Instantiate a ::Compiler
that can benchmark (time) it’s stages. For better or worse, the only way that they Benchmark library exposes it’s ::Benchmark::Report
is via a block, so this code also has to wrap with one
31 32 33 34 35 36 37 38 |
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 31 def self.with_benchmarks(options:, runtime:, &block) ::Benchmark.benchmark(::Benchmark::CAPTION, 25, ::Benchmark::FORMAT, '> Total') do |x| # compiler.extend(self) compiler = new(benchmark: x, options:, runtime:) block.call(compiler) [compiler.timings.reduce(:+)] end end |
Instance Method Details
#outputting!(&block) ⇒ Object
Time the Compiler#outputting! stage rubocop:disable Naming/BlockForwarding
58 59 60 |
# File 'lib/csv_plus_plus/benchmarked_compiler.rb', line 58 def outputting!(&block) time_stage('Writing the spreadsheet') { super(&block) } end |