Class: BenchmarkDriver::Output::Compare
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::Compare
- Defined in:
- lib/benchmark_driver/output/compare.rb
Overview
Compare output like benchmark-ips
Constant Summary collapse
- NAME_LENGTH =
20
Instance Method Summary collapse
-
#initialize(metrics:, jobs:, contexts:) ⇒ Compare
constructor
A new instance of Compare.
- #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:) ⇒ Compare
Returns a new instance of Compare.
8 9 10 11 12 13 |
# File 'lib/benchmark_driver/output/compare.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
81 82 83 84 85 86 87 88 |
# File 'lib/benchmark_driver/output/compare.rb', line 81 def report(result) @job_results << result if defined?(@job_context_result) @job_context_result[@job][@context] = result end $stdout.print("#{humanize(result.values.values.first, [10, @context.name.length].max)} ") 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 43 44 45 46 |
# File 'lib/benchmark_driver/output/compare.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(' %10s ' % context_name) end $stdout.puts end block.call end if @context_names.size > 1 compare_executables elsif @job_names.size > 1 compare_jobs end result end |
#with_context(context, &block) ⇒ Object
74 75 76 77 78 |
# File 'lib/benchmark_driver/output/compare.rb', line 74 def with_context(context, &block) @context = context @job_contexts << context block.call end |
#with_job(job, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/benchmark_driver/output/compare.rb', line 49 def with_job(job, &block) name = job.name if name.length > @name_length $stdout.puts(name) else $stdout.print("%#{@name_length}s" % name) end @job = name @job_results = [] @job_contexts = [] result = block.call $stdout.print(@metrics.first.unit) loop_count = @job_results.first.loop_count if loop_count && @job_results.all? { |r| r.loop_count == loop_count } $stdout.print(" - #{humanize(loop_count)} times") if @job_results.all? { |job_result| !job_result.duration.nil? } $stdout.print(" in") show_durations end end $stdout.puts result end |
#with_warmup(&block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/benchmark_driver/output/compare.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 |