Class: Baseline::OutputFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/baseline/output_format.rb

Instance Method Summary collapse

Instance Method Details

#bench_output(name, time, new_repeat, orig_repeat, nest_level) ⇒ Object



7
8
9
10
11
# File 'lib/baseline/output_format.rb', line 7

def bench_output(name, time, new_repeat, orig_repeat, nest_level)
  repeat = new_repeat || orig_repeat
  repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
  puts "#{indenter(nest_level)}#{name}: %0.2f seconds #{repeat_text}" % time
end

#compare_output(winner, loser, time_diff, time_ratio, nest_level) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/baseline/output_format.rb', line 49

def compare_output(winner, loser, time_diff, time_ratio, nest_level)
  if time_diff != 0
    puts "#{indenter(nest_level)}Comparison: \"#{winner}\" is faster than \"#{loser}\"" \
    " by %0.2f seconds (%0.2f times faster)" % [time_diff, time_ratio]
  else
    puts "#{indenter(nest_level)}Comparison: \"#{winner}\" is the same speed as \"#{loser}\"" 
  end
end


20
21
22
23
24
# File 'lib/baseline/output_format.rb', line 20

def context_output_footer(name, time, bench_count, subcontext_count, nest_level)
  puts "#{indenter(nest_level)}Total time: %0.2f seconds for #{name} " \
  "[#{bench_count} benches and #{subcontext_count} subcontexts]" % time
  puts "#{indenter(nest_level)}"
end

#context_output_header(name, new_repeat, orig_repeat, nest_level) ⇒ Object



13
14
15
16
17
18
# File 'lib/baseline/output_format.rb', line 13

def context_output_header(name, new_repeat, orig_repeat,  nest_level)
  repeat = new_repeat || orig_repeat
  repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
  puts "#{indenter(nest_level)}"
  puts "#{indenter(nest_level)}Benching #{name}: #{repeat_text}"
end

#context_skip(name) ⇒ Object



26
27
28
# File 'lib/baseline/output_format.rb', line 26

def context_skip(name)
  puts "[Skipping #{name}]"
end

#indenter(nest_level) ⇒ Object



3
4
5
# File 'lib/baseline/output_format.rb', line 3

def indenter(nest_level)
  " " * 2 * nest_level
end

#rank_output(ranking, nest_level) ⇒ Object



44
45
46
47
# File 'lib/baseline/output_format.rb', line 44

def rank_output(ranking, nest_level)
  quoted_ranking = ranking.map.with_index { |v, i| "#{i + 1}. \"#{v}\"" }.join(", ")
  puts "#{indenter(nest_level)}Rankings: #{quoted_ranking}"
end

#top_level_context_output_header(name, new_repeat, orig_repeat, nest_level) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/baseline/output_format.rb', line 34

def top_level_context_output_header(name, new_repeat, orig_repeat, nest_level)
  repeat = new_repeat || orig_repeat
  time_mode = Baseline.time_mode
  time_mode_text = time_mode != Baseline::TIME_MODE_DEFAULT ? "(time mode: #{time_mode})" : ""

  repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
  puts "#{indenter(nest_level)}"
  puts "#{indenter(nest_level)}Benching #{name}: #{repeat_text} #{time_mode_text}"      
end

#top_level_context_skip(name) ⇒ Object



30
31
32
# File 'lib/baseline/output_format.rb', line 30

def top_level_context_skip(name)
  puts "All Benchmarks disabled."
end