Class: Benchify

Inherits:
Object
  • Object
show all
Defined in:
lib/benchify.rb

Direct Known Subclasses

Benchmark

Constant Summary collapse

MESSAGE =
'processing time:'

Instance Attribute Summary collapse

Instance Method Summary collapse

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, message = 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 = message || MESSAGE
end

Instance Attribute Details

#dataObject (readonly) Also known as: result

Returns the value of attribute data.



5
6
7
# File 'lib/benchify.rb', line 5

def data
  @data
end

#endObject (readonly)

Returns the value of attribute end.



5
6
7
# File 'lib/benchify.rb', line 5

def end
  @end
end

#in_hoursObject (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_millisecondsObject (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_minutesObject (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_secondsObject (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

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/benchify.rb', line 5

def message
  @message
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/benchify.rb', line 5

def start
  @start
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/benchify.rb', line 5

def time
  @time
end

#totalObject (readonly)

Returns the value of attribute total.



5
6
7
# File 'lib/benchify.rb', line 5

def total
  @total
end

#typeObject (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

Yields:

  • (operation)


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    = message || @message
  @start = Time.now

  yield operation

  @end   = Time.now
  @total = (@end - @start).to_f

  calculate_time @type
  @data = "#{msg} #{@time} #{@type}"
end