Class: BenchmarkDriver::Output::Simple
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::Simple
- Defined in:
- lib/benchmark_driver/output/simple.rb
Constant Summary collapse
- NAME_LENGTH =
10
- OPTIONS =
{ humanize: ['--output-humanize true|false', TrueClass, 'Humanize result numbers (default: true)'], }
Instance Method Summary collapse
-
#initialize(metrics:, jobs:, contexts:, options:) ⇒ 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:, options:) ⇒ Simple
Returns a new instance of Simple.
11 12 13 14 15 16 |
# File 'lib/benchmark_driver/output/simple.rb', line 11 def initialize(metrics:, jobs:, contexts:, options:) @metrics = metrics @context_names = contexts.map(&:name) @name_length = jobs.map(&:name).map(&:size).max @humanize = .fetch(:humanize, true) end |
Instance Method Details
#report(result) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/benchmark_driver/output/simple.rb', line 67 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/benchmark_driver/output/simple.rb', line 28 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
62 63 64 |
# File 'lib/benchmark_driver/output/simple.rb', line 62 def with_context(context, &block) block.call end |
#with_job(job, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/benchmark_driver/output/simple.rb', line 50 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
18 19 20 21 22 23 24 25 26 |
# File 'lib/benchmark_driver/output/simple.rb', line 18 def with_warmup(&block) @with_benchmark = false without_stdout_buffering do $stdout.print 'warming up' block.call end ensure $stdout.puts end |