Class: EasyBench

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/easy_bench.rb

Defined Under Namespace

Classes: DataSet

Constant Summary collapse

VERSION =
'1.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil) ⇒ EasyBench

Returns a new instance of EasyBench.



11
12
13
# File 'lib/easy_bench.rb', line 11

def initialize(title=nil)
  @dataset = DataSet.new(title)
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



9
10
11
# File 'lib/easy_bench.rb', line 9

def dataset
  @dataset
end

Class Method Details

.log_times(logger, label) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/easy_bench.rb', line 33

def self.log_times(logger, label)
  start_time = Time.now
  logger.info('Starting ' + label + ' at ' + start_time.to_s)
  res = yield
  end_time = Time.now
  logger.info('Finished ' + label + ' at ' + end_time.to_s + ' (' + (end_time - start_time).to_s + 's)')
  res
end

Instance Method Details

#callerObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/easy_bench.rb', line 15

def caller
  start_time = Time.now
  res = yield
  elapsed_time = Time.now - start_time

  @dataset.runs << elapsed_time
  if @dataset.min_run_time.nil? || @dataset.min_run_time > elapsed_time
    @dataset.min_run_time = elapsed_time
  end
  if @dataset.max_run_time.nil? || @dataset.max_run_time < elapsed_time
    @dataset.max_run_time = elapsed_time
  end

  res
end