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 Method Summary collapse
-
#initialize(metrics:, jobs:, contexts:) ⇒ Markdown
constructor
A new instance of Markdown.
- #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:) ⇒ Markdown
Returns a new instance of Markdown.
7 8 9 10 11 |
# File 'lib/benchmark_driver/output/markdown.rb', line 7 def initialize(metrics:, jobs:, contexts:) @metrics = metrics @context_names = contexts.map(&:name) @name_length = jobs.map(&:name).map(&:size).max end |
Instance Method Details
#report(result) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/benchmark_driver/output/markdown.rb', line 66 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
22 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/markdown.rb', line 22 def with_benchmark(&block) @with_benchmark = true without_stdout_buffering do # Show header $stdout.puts "# #{@metrics.first.name} (#{@metrics.first.unit})\n\n" # Show executable names $stdout.print("|#{' ' * @name_length} ") @context_names.each do |context_name| $stdout.print("|%#{NAME_LENGTH}s" % context_name) # same size as humanize end $stdout.puts('|') # Show header separator $stdout.print("|:#{'-' * (@name_length - 1)}--") @context_names.each do |context_name| $stdout.print("|:#{'-' * (NAME_LENGTH - 1)}") # same size as humanize end $stdout.puts('|') block.call end rescue @with_benchmark = false end |
#with_context(context, &block) ⇒ Object
61 62 63 |
# File 'lib/benchmark_driver/output/markdown.rb', line 61 def with_context(context, &block) block.call end |
#with_job(job, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/benchmark_driver/output/markdown.rb', line 49 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
13 14 15 16 17 18 19 20 |
# File 'lib/benchmark_driver/output/markdown.rb', line 13 def with_warmup(&block) without_stdout_buffering do $stdout.print 'warming up' block.call end ensure $stdout.puts end |