Class: BenchmarkDriver::Output::Simple

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/output/simple.rb

Constant Summary collapse

NAME_LENGTH =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jobs:, executables:) ⇒ Simple

Returns a new instance of Simple.

Parameters:

  • jobs (Array<BenchmarkDriver::*::Job>)
  • executables (Array<BenchmarkDriver::Config::Executable>)


9
10
11
12
13
# File 'lib/benchmark_driver/output/simple.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)

Parameters:

  • metrics_type (BenchmarkDriver::Metrics::Type)


5
6
7
# File 'lib/benchmark_driver/output/simple.rb', line 5

def metrics_type=(value)
  @metrics_type = value
end

Instance Method Details

#report(metrics) ⇒ Object

Parameters:



58
59
60
61
62
63
64
# File 'lib/benchmark_driver/output/simple.rb', line 58

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
# File 'lib/benchmark_driver/output/simple.rb', line 24

def with_benchmark(&block)
  @with_benchmark = true
  without_stdout_buffering do
    # Show header
    $stdout.puts "benchmark results (#{@metrics_type.unit}):"

    # Show executable names
    if @executables.size > 1
      $stdout.print("#{' ' * @name_length}  ")
      @executables.each do |executable|
        $stdout.print("%#{NAME_LENGTH}s  " % executable.name)
      end
      $stdout.puts
    end

    block.call
  end
rescue
  @with_benchmark = false
end

#with_job(job, &block) ⇒ Object

Parameters:



46
47
48
49
50
51
52
53
54
55
# File 'lib/benchmark_driver/output/simple.rb', line 46

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/simple.rb', line 15

def with_warmup(&block)
  without_stdout_buffering do
    $stdout.print 'warming up'
    block.call
  end
ensure
  $stdout.puts
end