Class: SemiStatic::Statistics
- Inherits:
-
Object
- Object
- SemiStatic::Statistics
- Defined in:
- lib/semi-static/statistics.rb
Overview
Used to track statistics while generating the Site.
Instance Method Summary collapse
-
#display ⇒ Object
Display the collected data to the user.
-
#initialize ⇒ Statistics
constructor
Initialize a new Statistics object.
-
#record(category, item) ⇒ Object
Record the time it takes for the block to execute.
-
#reset ⇒ Object
Clears all recorded data.
Constructor Details
#initialize ⇒ Statistics
Initialize a new Statistics object.
7 8 9 |
# File 'lib/semi-static/statistics.rb', line 7 def initialize self.reset end |
Instance Method Details
#display ⇒ Object
Display the collected data to the user.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/semi-static/statistics.rb', line 32 def display # details = {} @data.each do |category,items| next if category == :site sum = 0; items.values.each { |time| sum += time } list = items.sort { |l,r| l.last <=> r.last } if list.length > 1 printf "%10s c:%-3d sum:%9.6f min:%.6f max:%.6f avg:%.6f\n", category, items.length, sum, list.first.last, list.last.last, sum / items.length # details[category] = list.reverse.first(5).collect { |pair| { pair.first => pair.last } } else printf "%10s c:%-3d sum:%9.6f\n", category, items.length, sum end end puts '---' @data[:site].each { |cat,time| printf "%15s %9.6f\n", cat.to_s.capitalize, time } # unless details.empty? # puts '---' # puts # puts details.to_yaml # end end |
#record(category, item) ⇒ Object
Record the time it takes for the block to execute.
category: The category of the action. item: The name of the action.
22 23 24 25 26 27 28 |
# File 'lib/semi-static/statistics.rb', line 22 def record(category, item) raise ArgumentError unless block_given? before = Time.now result = yield @data[category][item] = Time.now - before return result end |