Class: Benchmark
- Inherits:
-
Object
- Object
- Benchmark
- Defined in:
- lib/benchify/benchmark.rb
Direct Known Subclasses
Constant Summary collapse
- MESSAGE =
'processing time:'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#middle ⇒ Object
(also: #time)
readonly
Returns the value of attribute middle.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#msg ⇒ Object
(also: #message)
readonly
Returns the value of attribute msg.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(message = nil) {|operation| ... } ⇒ Object (also: #measure)
- #finish ⇒ Object (also: #end)
-
#initialize(type = :sec, message = nil) ⇒ Benchmark
constructor
A new instance of Benchmark.
Constructor Details
#initialize(type = :sec, message = nil) ⇒ Benchmark
Returns a new instance of Benchmark.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/benchify/benchmark.rb', line 13 def initialize( type = :sec, = nil ) case type when :m, :min, :minute, :minutes then :min when :ms, :milli, :milliseconds then :ms when :h, :hour, :hours then :h else :sec end @data = [] @type = type @msg = || MESSAGE end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def data @data end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def max @max end |
#middle ⇒ Object (readonly) Also known as: time
Returns the value of attribute middle.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def middle @middle end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def min @min end |
#msg ⇒ Object (readonly) Also known as: message
Returns the value of attribute msg.
7 8 9 |
# File 'lib/benchify/benchmark.rb', line 7 def msg @msg end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def result @result end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
8 9 10 |
# File 'lib/benchify/benchmark.rb', line 8 def results @results end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/benchify/benchmark.rb', line 7 def type @type end |
Instance Method Details
#call(message = nil) {|operation| ... } ⇒ Object Also known as: measure
25 26 27 28 29 30 31 |
# File 'lib/benchify/benchmark.rb', line 25 def call( = nil, &operation ) @msg = unless .nil? start = Time.now yield operation ends = Time.now @data << [ start, ends ] end |
#finish ⇒ Object Also known as: end
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/benchify/benchmark.rb', line 35 def finish @results = Result.new @type, @msg @data.each do |st, en| @results.add st, en end @results.get @min = @results.min @max = @results.max @middle = @results.middle @result = @results.output end |