Class: Benchmark::Output::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/output/markdown.rb

Constant Summary collapse

REQUIRED_FIELDS =

This class requires runner to measure following fields in ‘Benchmark::Driver::BenchmarkResult` to show output.

[:real]

Instance Method Summary collapse

Constructor Details

#initialize(jobs:, executables:, options:) ⇒ Markdown

Returns a new instance of Markdown.



8
9
10
11
12
13
# File 'lib/benchmark/output/markdown.rb', line 8

def initialize(jobs:, executables:, options:)
  @jobs = jobs
  @executables = executables
  @options = options
  @name_length = jobs.map { |j| j.name.size }.max
end

Instance Method Details

#benchmark_stats(result) ⇒ Object

Parameters:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/benchmark/output/markdown.rb', line 52

def benchmark_stats(result)
  if @options.compare
    if @ran_num == 0
      @base_real = result.real
      $stdout.print('%-10.2f |' % 1)
    else
      $stdout.print('%-10.2f |' % (@base_real / result.real))
    end
  else
    $stdout.print('%-10.3f |' % result.real)
  end

  @ran_num += 1
  if @ran_num == @executables.size
    $stdout.puts
  end
end

#finishObject



70
71
72
# File 'lib/benchmark/output/markdown.rb', line 70

def finish
  # compare is done in table
end

#running(name) ⇒ Object

Parameters:

  • name (String)


46
47
48
49
# File 'lib/benchmark/output/markdown.rb', line 46

def running(name)
  $stdout.print("|%-#{@name_length}s|" % name)
  @ran_num = 0
end

#start_runningObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/benchmark/output/markdown.rb', line 29

def start_running
  $stdout.puts if @jobs.any?(&:warmup_needed?)

  $stdout.print("|#{' ' * @name_length}|")
  @executables.each do |executable|
    $stdout.print('%-10s |' % executable.name)
  end
  $stdout.puts

  $stdout.print("|:#{'-' * (@name_length-1)}|")
  @executables.each do |executable|
    $stdout.print(":#{'-' * 10}|")
  end
  $stdout.puts
end

#start_warmingObject



15
16
17
# File 'lib/benchmark/output/markdown.rb', line 15

def start_warming
  $stdout.print 'warming up...'
end

#warming(name) ⇒ Object

Parameters:

  • name (String)


20
21
22
# File 'lib/benchmark/output/markdown.rb', line 20

def warming(name)
  # noop
end

#warmup_stats(result) ⇒ Object

Parameters:



25
26
27
# File 'lib/benchmark/output/markdown.rb', line 25

def warmup_stats(result)
  $stdout.print '.'
end