Class: EasyBench::DataSet
- Inherits:
-
Object
- Object
- EasyBench::DataSet
- Includes:
- SometimesMemoize
- Defined in:
- lib/easy_bench.rb
Instance Attribute Summary collapse
-
#max_run_time ⇒ Object
Returns the value of attribute max_run_time.
-
#min_run_time ⇒ Object
Returns the value of attribute min_run_time.
-
#runs ⇒ Object
Returns the value of attribute runs.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #ave_run_time ⇒ Object
- #draw_bars(include_values = false) ⇒ Object
-
#initialize(title) ⇒ DataSet
constructor
A new instance of DataSet.
- #print_table ⇒ Object
- #report(bars = false) ⇒ Object
- #stats ⇒ Object
- #total_run_time ⇒ Object
- #total_runs ⇒ Object
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_time ⇒ Object
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_time ⇒ Object
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 |
#runs ⇒ Object
Returns the value of attribute runs.
45 46 47 |
# File 'lib/easy_bench.rb', line 45 def runs @runs end |
#title ⇒ Object (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_time ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/easy_bench.rb', line 62 def ave_run_time tr = self.total_runs if 0 == tr nil else (self.total_run_time / self.total_runs) end end |
#draw_bars(include_values = false) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/easy_bench.rb', line 106 def (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| = [] @runs.each do |run| if run >= min_run_time + (band.to_f * band_height) << '*' else << ' ' end end puts .join(' ') end end puts runs.join(' ') if include_values end |
#print_table ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/easy_bench.rb', line 98 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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/easy_bench.rb', line 71 def report(=false) memoizing do if @title puts @title puts end print_table if puts end puts end end |
#stats ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/easy_bench.rb', line 86 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_time ⇒ Object
57 58 59 |
# File 'lib/easy_bench.rb', line 57 def total_run_time @runs.inject(0.0){|sum, run| sum + run} end |
#total_runs ⇒ Object
53 54 55 |
# File 'lib/easy_bench.rb', line 53 def total_runs @runs.size end |