Class: BenchmarkDriver::Output::Markdown
- Inherits:
-
Object
- Object
- BenchmarkDriver::Output::Markdown
- Defined in:
- lib/benchmark_driver/output/markdown.rb
Constant Summary collapse
- NAME_LENGTH =
8
Instance Attribute Summary collapse
- #metrics_type ⇒ Object writeonly
Instance Method Summary collapse
-
#initialize(jobs:, executables:) ⇒ Markdown
constructor
A new instance of Markdown.
- #report(metrics) ⇒ Object
- #with_benchmark(&block) ⇒ Object
- #with_job(job, &block) ⇒ Object
- #with_warmup(&block) ⇒ Object
Constructor Details
#initialize(jobs:, executables:) ⇒ Markdown
Returns a new instance of Markdown.
9 10 11 12 13 |
# File 'lib/benchmark_driver/output/markdown.rb', line 9 def initialize(jobs:, executables:) @jobs = jobs @executables = executables @name_length = jobs.map { |j| j.name.size }.max end |
Instance Attribute Details
#metrics_type=(value) ⇒ Object (writeonly)
5 6 7 |
# File 'lib/benchmark_driver/output/markdown.rb', line 5 def metrics_type=(value) @metrics_type = value end |
Instance Method Details
#report(metrics) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/benchmark_driver/output/markdown.rb', line 63 def report(metrics) if @with_benchmark $stdout.print("|%#{NAME_LENGTH}s" % humanize(metrics.value)) else $stdout.print '.' end end |
#with_benchmark(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/benchmark_driver/output/markdown.rb', line 24 def with_benchmark(&block) @with_benchmark = true without_stdout_buffering do # Show header $stdout.puts "# benchmark results (#{@metrics_type.unit})\n\n" # Show executable names $stdout.print("|#{' ' * @name_length} ") @executables.each do |executable| $stdout.print("|%#{NAME_LENGTH}s" % executable.name) # same size as humanize end $stdout.puts('|') # Show header separator $stdout.print("|:#{'-' * (@name_length - 1)}--") @executables.each do |executable| $stdout.print("|:#{'-' * (NAME_LENGTH - 1)}") # same size as humanize end $stdout.puts('|') block.call end rescue @with_benchmark = false end |
#with_job(job, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/benchmark_driver/output/markdown.rb', line 51 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
15 16 17 18 19 20 21 22 |
# File 'lib/benchmark_driver/output/markdown.rb', line 15 def with_warmup(&block) without_stdout_buffering do $stdout.print 'warming up' block.call end ensure $stdout.puts end |