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 Attribute Summary collapse
- #metrics_type ⇒ Object writeonly
Instance Method Summary collapse
-
#initialize(jobs:, executables:) ⇒ Compare
constructor
A new instance of Compare.
- #report(metrics) ⇒ Object
- #with_benchmark(&block) ⇒ Object
- #with_job(job, &block) ⇒ Object
- #with_warmup(&block) ⇒ Object
Constructor Details
#initialize(jobs:, executables:) ⇒ Compare
10 11 12 13 |
# File 'lib/benchmark_driver/output/compare.rb', line 10 def initialize(jobs:, executables:) @jobs = jobs @executables = executables end |
Instance Attribute Details
#metrics_type=(value) ⇒ Object (writeonly)
6 7 8 |
# File 'lib/benchmark_driver/output/compare.rb', line 6 def metrics_type=(value) @metrics_type = value end |
Instance Method Details
#report(metrics) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/benchmark_driver/output/compare.rb', line 69 def report(metrics) if defined?(@metrics_by_job) @metrics_by_job[@current_job] << metrics end @job_metrics << metrics $stdout.print("#{humanize(metrics.value, [10, metrics.executable.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 |
# File 'lib/benchmark_driver/output/compare.rb', line 23 def with_benchmark(&block) @metrics_by_job = Hash.new { |h, k| h[k] = [] } without_stdout_buffering do $stdout.puts 'Calculating -------------------------------------' if @executables.size > 1 $stdout.print(' ' * NAME_LENGTH) @executables.each do |executable| $stdout.print(' %10s ' % executable.name) end $stdout.puts end block.call end ensure if @executables.size > 1 compare_executables elsif @jobs.size > 1 compare_jobs end end |
#with_job(job, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/benchmark_driver/output/compare.rb', line 47 def with_job(job, &block) if job.name.length > NAME_LENGTH $stdout.puts(job.name) else $stdout.print("%#{NAME_LENGTH}s" % job.name) end @current_job = job @job_metrics = [] block.call ensure $stdout.print(@metrics_type.unit) if job.respond_to?(:loop_count) && job.loop_count $stdout.print(" - #{humanize(job.loop_count)} times") if @job_metrics.all? { |metrics| metrics.duration } $stdout.print(" in") show_durations end end $stdout.puts 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 |