Class: BenchmarkDriver::Output::Simple
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::Simple
- Defined in:
- lib/benchmark_driver/output/simple.rb
Constant Summary collapse
- NAME_LENGTH =
8
Instance Attribute Summary collapse
- #metrics_type ⇒ Object writeonly
Instance Method Summary collapse
-
#initialize(jobs:, executables:) ⇒ Simple
constructor
A new instance of Simple.
- #report(metrics) ⇒ Object
- #with_benchmark(&block) ⇒ Object
- #with_job(job, &block) ⇒ Object
- #with_warmup(&block) ⇒ Object
Constructor Details
#initialize(jobs:, executables:) ⇒ Simple
Returns a new instance of Simple.
9 10 11 12 13 |
# File 'lib/benchmark_driver/output/simple.rb', line 9 def initialize(jobs:, executables:) @jobs = jobs @executables = executables @name_length = jobs.map { |j| j.name.size }.max end |
Instance Attribute Details
#metrics_type=(value) ⇒ Object (writeonly)
5 6 7 |
# File 'lib/benchmark_driver/output/simple.rb', line 5 def metrics_type=(value) @metrics_type = value end |
Instance Method Details
#report(metrics) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/benchmark_driver/output/simple.rb', line 58 def report(metrics) if @with_benchmark $stdout.print("%#{NAME_LENGTH}s " % humanize(metrics.value)) else $stdout.print '.' end end |
#with_benchmark(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/benchmark_driver/output/simple.rb', line 24 def with_benchmark(&block) @with_benchmark = true without_stdout_buffering do # Show header $stdout.puts "benchmark results (#{@metrics_type.unit}):" # Show executable names if @executables.size > 1 $stdout.print("#{' ' * @name_length} ") @executables.each do |executable| $stdout.print("%#{NAME_LENGTH}s " % executable.name) end $stdout.puts end block.call end rescue @with_benchmark = false end |
#with_job(job, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/benchmark_driver/output/simple.rb', line 46 def with_job(job, &block) if @with_benchmark $stdout.print("%-#{@name_length}s " % job.name) end block.call ensure if @with_benchmark $stdout.puts end end |
#with_warmup(&block) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/benchmark_driver/output/simple.rb', line 15 def with_warmup(&block) without_stdout_buffering do $stdout.print 'warming up' block.call end ensure $stdout.puts end |