Class: Measure

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

Instance Method Summary collapse

Constructor Details

#initializeMeasure

Returns a new instance of Measure.



3
4
5
# File 'lib/measure.rb', line 3

def initialize()
  start()
end

Instance Method Details

#exection_timeObject



24
25
26
# File 'lib/measure.rb', line 24

def exection_time()
  Time.now - @start_time
end

#parse_caller(at) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/measure.rb', line 28

def parse_caller(at)
  if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
    file = $1
    line = $2.to_i
    method = $3
    [file, line, method]
  end
end

#resetObject



20
21
22
# File 'lib/measure.rb', line 20

def reset()
  start()
end

#startObject



16
17
18
# File 'lib/measure.rb', line 16

def start()
  @start_time = Time.now
end

#to_sObject



7
8
9
10
11
12
13
14
# File 'lib/measure.rb', line 7

def to_s
  ret = []
  file, line, method = parse_caller(caller.first)
  ret << "Exection Time: #{exection_time()} [sec]"
  ret << "FileName: #{file}, Method: #{method}, Line: #{line}"
  ret << "\n"
  ret.join("\n")    
end