Class: EasyBench::DataSet

Inherits:
Object
  • Object
show all
Includes:
SometimesMemoize
Defined in:
lib/easy_bench.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ DataSet

Returns a new instance of DataSet.



48
49
50
51
# File 'lib/easy_bench.rb', line 48

def initialize(title)
  @title = title
  @runs = []
end

Instance Attribute Details

#max_run_timeObject

Returns the value of attribute max_run_time.



45
46
47
# File 'lib/easy_bench.rb', line 45

def max_run_time
  @max_run_time
end

#min_run_timeObject

Returns the value of attribute min_run_time.



45
46
47
# File 'lib/easy_bench.rb', line 45

def min_run_time
  @min_run_time
end

#runsObject

Returns the value of attribute runs.



45
46
47
# File 'lib/easy_bench.rb', line 45

def runs
  @runs
end

#titleObject (readonly)

Returns the value of attribute title.



46
47
48
# File 'lib/easy_bench.rb', line 46

def title
  @title
end

Instance Method Details

#ave_run_timeObject



62
63
64
# File 'lib/easy_bench.rb', line 62

def ave_run_time
  (self.total_run_time / self.total_runs)
end

#draw_bars(include_values = false) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/easy_bench.rb', line 101

def draw_bars(include_values=false)
  if total_runs > 0
    band_height = (max_run_time - min_run_time) / 4.0
    (0..4).to_a.reverse.each do |band|
      bars = []
      @runs.each do |run|
        if run >= min_run_time + (band.to_f * band_height)
          bars << '*'
        else
          bars << ' '
        end
      end
      puts bars.join(' ')
    end
  end
  puts runs.join(' ') if include_values
end


93
94
95
96
97
98
99
# File 'lib/easy_bench.rb', line 93

def print_table
  puts "num runs       : #{total_runs}"
  puts "total run time : #{total_run_time}s"
  puts "min run time   : #{min_run_time}s"
  puts "max run time   : #{max_run_time}s"
  puts "ave run time   : #{ave_run_time}s"
end

#report(bars = false) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/easy_bench.rb', line 66

def report(bars=false)
  memoizing do
    if @title
      puts @title
      puts
    end
    print_table
    if bars
      puts
      draw_bars
    end
    puts
  end
end

#statsObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/easy_bench.rb', line 81

def stats
  memoizing do
    {
      :count => total_runs,
      :total => total_run_time,
      :min => min_run_time,
      :max => max_run_time,
      :mean => ave_run_time
    }
  end
end

#total_run_timeObject



57
58
59
# File 'lib/easy_bench.rb', line 57

def total_run_time
  @runs.inject(0.0){|sum, run| sum + run}
end

#total_runsObject



53
54
55
# File 'lib/easy_bench.rb', line 53

def total_runs
  @runs.size
end