Class: BenchmarkDriver::Output::Simple
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::Simple
- Defined in:
- lib/benchmark_driver/output/simple.rb
Constant Summary collapse
- NAME_LENGTH =
10
Instance Method Summary collapse
-
#initialize(metrics:, jobs:, contexts:) ⇒ Simple
constructor
A new instance of Simple.
- #report(result) ⇒ Object
- #with_benchmark(&block) ⇒ Object
- #with_context(context, &block) ⇒ Object
- #with_job(job, &block) ⇒ Object
- #with_warmup(&block) ⇒ Object
Constructor Details
#initialize(metrics:, jobs:, contexts:) ⇒ Simple
Returns a new instance of Simple.
7 8 9 10 11 |
# File 'lib/benchmark_driver/output/simple.rb', line 7 def initialize(metrics:, jobs:, contexts:) @metrics = metrics @context_names = contexts.map(&:name) @name_length = jobs.map(&:name).map(&:size).max end |
Instance Method Details
#report(result) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/benchmark_driver/output/simple.rb', line 62 def report(result) if @with_benchmark $stdout.print("%#{NAME_LENGTH}s " % humanize(result.values.fetch(@metrics.first))) else $stdout.print '.' end end |
#with_benchmark(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/benchmark_driver/output/simple.rb', line 23 def with_benchmark(&block) @with_benchmark = true without_stdout_buffering do # Show header $stdout.puts "#{@metrics.first.name} (#{@metrics.first.unit}):" # Show executable names if @context_names.size > 1 $stdout.print("#{' ' * @name_length} ") @context_names.each do |context_name| $stdout.print("%#{NAME_LENGTH}s " % context_name) end $stdout.puts end block.call end ensure @with_benchmark = false end |
#with_context(context, &block) ⇒ Object
57 58 59 |
# File 'lib/benchmark_driver/output/simple.rb', line 57 def with_context(context, &block) block.call end |
#with_job(job, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/benchmark_driver/output/simple.rb', line 45 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
13 14 15 16 17 18 19 20 21 |
# File 'lib/benchmark_driver/output/simple.rb', line 13 def with_warmup(&block) @with_benchmark = false without_stdout_buffering do $stdout.print 'warming up' block.call end ensure $stdout.puts end |