Class: CompareTime

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

Overview

CompareTime.new.compare(:whatever_name_you_want)

...

.with(:whatever_name_you_want2)

...

.print_results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompareTime

Returns a new instance of CompareTime.



14
15
16
17
# File 'lib/compare_time.rb', line 14

def initialize()
  # add how many times
  @benchmarks = {}
end

Instance Attribute Details

#benchmarksObject (readonly)

Returns the value of attribute benchmarks.



12
13
14
# File 'lib/compare_time.rb', line 12

def benchmarks
  @benchmarks
end

Instance Method Details

#compare(symbol, &block) ⇒ Object Also known as: with



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

def compare(symbol, &block)
  execute_and_save(symbol, block)
  self
end


30
31
32
33
34
35
36
# File 'lib/compare_time.rb', line 30

def print_results
  puts results[0].colorize(:green)

  results.drop(1).each do |res|
    puts res
  end
end

#resultsObject



24
25
26
27
28
# File 'lib/compare_time.rb', line 24

def results
  @benchmarks.sort_by(&:last).map do |arr|
    "#{arr[0]}: #{'%.10f' % arr[1]}"
  end
end