Class: BenchmarkX::Report

Inherits:
Benchmark::Report
  • Object
show all
Defined in:
lib/benchmarkx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = 0, fmtstr = nil) ⇒ Report

Returns a new instance of Report.



107
108
109
110
111
112
113
114
# File 'lib/benchmarkx.rb', line 107

def initialize(width = 0, fmtstr = nil)
  initialize_orig(width, fmtstr)
  @gruff = Gruff::SideBar.new
  @gruff.x_axis_label = "sec"
  @gruff.sort = false
  @labels, @utimes, @stimes, @totals, @reals = [], [], [], [], []
  @filename = "graph.png"
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



102
103
104
# File 'lib/benchmarkx.rb', line 102

def filename
  @filename
end

#gruffObject (readonly)

Returns the value of attribute gruff.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def gruff
  @gruff
end

#labelsObject (readonly)

Returns the value of attribute labels.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def labels
  @labels
end

#realsObject (readonly)

Returns the value of attribute reals.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def reals
  @reals
end

#stimesObject (readonly)

Returns the value of attribute stimes.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def stimes
  @stimes
end

#totalsObject (readonly)

Returns the value of attribute totals.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def totals
  @totals
end

#utimesObject (readonly)

Returns the value of attribute utimes.



103
104
105
# File 'lib/benchmarkx.rb', line 103

def utimes
  @utimes
end

Instance Method Details

#initialize_origObject



105
# File 'lib/benchmarkx.rb', line 105

alias :initialize_orig :initialize

#item(label = "", *fmt, &blk) ⇒ Object Also known as: report



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/benchmarkx.rb', line 116

def item(label = "", *fmt, &blk)
  # copied from benchmark.rb
  print label.ljust(@width)
  res = Benchmark::measure(&blk)
  print res.format(@fmtstr, *fmt)

  # new
  record(label, res)

  # copied from benchmark.rb
  res
end

#record(label, time) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/benchmarkx.rb', line 131

def record(label,time)
  @labels << label
  @utimes << time.utime
  @stimes << time.stime
  @totals << time.total
  @reals << time.real
end

#renderObject



139
140
141
142
143
144
145
146
147
# File 'lib/benchmarkx.rb', line 139

def render
  @labels.each_with_index{|label, idx| @gruff.labels[idx] = label }
  @gruff.data("user", @utimes)
  @gruff.data("system", @stimes)
  @gruff.data("total", @totals)
  @gruff.data("real", @reals)
  @gruff.write(@filename)
  return self
end