Class: CompareTime
- Inherits:
-
Object
- Object
- CompareTime
- 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
-
#benchmarks ⇒ Object
readonly
Returns the value of attribute benchmarks.
Instance Method Summary collapse
- #compare(symbol, &block) ⇒ Object (also: #with)
-
#initialize ⇒ CompareTime
constructor
A new instance of CompareTime.
- #print_results ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize ⇒ CompareTime
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
#benchmarks ⇒ Object (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 |
#print_results ⇒ Object
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 |
#results ⇒ Object
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 |