Class: BenchmarkDriver::Output::All
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::All
- Defined in:
- lib/benchmark_driver/output/all.rb
Constant Summary collapse
- NAME_LENGTH =
20- CONTEXT_LENGTH =
20
Instance Method Summary collapse
-
#initialize(metrics:, jobs:, contexts:) ⇒ All
constructor
A new instance of All.
- #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:) ⇒ All
Returns a new instance of All.
8 9 10 11 12 13 |
# File 'lib/benchmark_driver/output/all.rb', line 8 def initialize(metrics:, jobs:, contexts:) @metrics = metrics @job_names = jobs.map(&:name) @context_names = contexts.map(&:name) @name_length = [@job_names.map(&:length).max, NAME_LENGTH].max end |
Instance Method Details
#report(result) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/benchmark_driver/output/all.rb', line 58 def report(result) if result.all_values.nil? || !defined?(@context_values) $stdout.puts(" %#{[CONTEXT_LENGTH, @context.name.length].max}s " % result.values.values.first.to_s) return end num_values = result.all_values.values.first.size if @context_values.empty? print("\r") else print("\e[#{num_values}F") end @context_values[@context] = result.all_values.values.first.sort precision = result.values.values.first.to_s.sub(/\A\d+\./, '').length num_values.times do |i| if i == 0 $stdout.print(@job_name) else print(" " * [@job_name.length, NAME_LENGTH].max) end @context_values.each do |context, values| $stdout.print(" %#{[CONTEXT_LENGTH, context.name.length].max}.#{precision}f " % values[i]) end (@context_names - @context_values.keys.map(&:name)).each do |context_name| print(" " * ([CONTEXT_LENGTH, context_name.length].max + 2)) end if i == 0 $stdout.puts(@metrics.first.unit) else $stdout.puts end 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 |
# File 'lib/benchmark_driver/output/all.rb', line 23 def with_benchmark(&block) @job_context_result = Hash.new do |hash, job| hash[job] = {} end result = without_stdout_buffering do $stdout.puts 'Calculating -------------------------------------' if @context_names.size > 1 $stdout.print(' ' * @name_length) @context_names.each do |context_name| $stdout.print(" %#{CONTEXT_LENGTH}s " % context_name) end $stdout.puts end block.call end result end |
#with_context(context, &block) ⇒ Object
52 53 54 55 |
# File 'lib/benchmark_driver/output/all.rb', line 52 def with_context(context, &block) @context = context block.call end |
#with_job(job, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/benchmark_driver/output/all.rb', line 44 def with_job(job, &block) @job_name = "%#{@name_length}s" % job.name $stdout.print(@job_name) @context_values = {} block.call end |
#with_warmup(&block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/benchmark_driver/output/all.rb', line 15 def with_warmup(&block) without_stdout_buffering do $stdout.puts 'Warming up --------------------------------------' # TODO: show exec name if it has multiple ones block.call end end |