Class: Benchmark::Output::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/output/time.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:) ⇒ Time

Returns a new instance of Time.



8
9
10
11
12
13
# File 'lib/benchmark/output/time.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:



46
47
48
49
50
51
52
# File 'lib/benchmark/output/time.rb', line 46

def benchmark_stats(result)
  $stdout.print('%-6.3f  ' % result.real)
  @ran_num += 1
  if @ran_num == @executables.size
    $stdout.puts
  end
end

#finishObject



54
55
56
# File 'lib/benchmark/output/time.rb', line 54

def finish
  # compare is not implemented yet
end

#running(name) ⇒ Object

Parameters:

  • name (String)


40
41
42
43
# File 'lib/benchmark/output/time.rb', line 40

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

#start_runningObject



29
30
31
32
33
34
35
36
37
# File 'lib/benchmark/output/time.rb', line 29

def start_running
  $stdout.puts if @jobs.any?(&:warmup_needed?)
  $stdout.puts 'benchmark results (s):'
  $stdout.print("%-#{@name_length}s  " % 'ruby')
  @executables.each do |executable|
    $stdout.print('%-6s  ' % executable.name)
  end
  $stdout.puts
end

#start_warmingObject



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

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

#warming(name) ⇒ Object

Parameters:

  • name (String)


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

def warming(name)
  # noop
end

#warmup_stats(result) ⇒ Object

Parameters:



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

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