Class: Benchify
- Inherits:
-
Object
- Object
- Benchify
- Defined in:
- lib/benchify.rb
Direct Known Subclasses
Constant Summary collapse
- MESSAGE =
'processing time:'
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #result)
readonly
Returns the value of attribute data.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#in_hours ⇒ Object
(also: #in_h)
readonly
Returns the value of attribute in_hours.
-
#in_milliseconds ⇒ Object
(also: #in_ms, #in_milli)
readonly
Returns the value of attribute in_milliseconds.
-
#in_minutes ⇒ Object
(also: #in_min)
readonly
Returns the value of attribute in_minutes.
-
#in_seconds ⇒ Object
(also: #in_sec)
readonly
Returns the value of attribute in_seconds.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(msg = nil) {|operation| ... } ⇒ Object (also: #measure)
-
#initialize(type = :sec, message = nil) ⇒ Benchify
constructor
A new instance of Benchify.
Constructor Details
#initialize(type = :sec, message = nil) ⇒ Benchify
Returns a new instance of Benchify.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/benchify.rb', line 20 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 @type = type = || MESSAGE end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: result
Returns the value of attribute data.
5 6 7 |
# File 'lib/benchify.rb', line 5 def data @data end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
5 6 7 |
# File 'lib/benchify.rb', line 5 def end @end end |
#in_hours ⇒ Object (readonly) Also known as: in_h
Returns the value of attribute in_hours.
6 7 8 |
# File 'lib/benchify.rb', line 6 def in_hours @in_hours end |
#in_milliseconds ⇒ Object (readonly) Also known as: in_ms, in_milli
Returns the value of attribute in_milliseconds.
6 7 8 |
# File 'lib/benchify.rb', line 6 def in_milliseconds @in_milliseconds end |
#in_minutes ⇒ Object (readonly) Also known as: in_min
Returns the value of attribute in_minutes.
6 7 8 |
# File 'lib/benchify.rb', line 6 def in_minutes @in_minutes end |
#in_seconds ⇒ Object (readonly) Also known as: in_sec
Returns the value of attribute in_seconds.
6 7 8 |
# File 'lib/benchify.rb', line 6 def in_seconds @in_seconds end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/benchify.rb', line 5 def end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
5 6 7 |
# File 'lib/benchify.rb', line 5 def start @start end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/benchify.rb', line 5 def time @time end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
5 6 7 |
# File 'lib/benchify.rb', line 5 def total @total end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/benchify.rb', line 5 def type @type end |
Instance Method Details
#call(msg = nil) {|operation| ... } ⇒ Object Also known as: measure
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/benchify.rb', line 34 def call( msg = nil, &operation ) msg = || @start = Time.now yield operation @end = Time.now @total = (@end - @start).to_f calculate_time @type @data = "#{msg} #{@time} #{@type}" end |