Class: Asciidoctor::Timings
- Inherits:
-
Object
- Object
- Asciidoctor::Timings
- Defined in:
- lib/asciidoctor/timings.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize ⇒ Timings
constructor
A new instance of Timings.
- #parse ⇒ Object
- #print_report(to = $stdout, subject = nil) ⇒ Object
- #read ⇒ Object
- #read_parse ⇒ Object
- #read_parse_convert ⇒ Object
- #record(key) ⇒ Object
- #start(key) ⇒ Object
- #time(*keys) ⇒ Object
- #total ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize ⇒ Timings
Returns a new instance of Timings.
4 5 6 7 |
# File 'lib/asciidoctor/timings.rb', line 4 def initialize @log = {} @timers = {} end |
Instance Method Details
#convert ⇒ Object
34 35 36 |
# File 'lib/asciidoctor/timings.rb', line 34 def convert time :convert end |
#parse ⇒ Object
26 27 28 |
# File 'lib/asciidoctor/timings.rb', line 26 def parse time :parse end |
#print_report(to = $stdout, subject = nil) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/asciidoctor/timings.rb', line 50 def print_report to = $stdout, subject = nil to.puts %(Input file: #{subject}) if subject to.puts %( Time to read and parse source: #{sprintf '%05.5f', read_parse.to_f}) to.puts %( Time to convert document: #{sprintf '%05.5f', convert.to_f}) to.puts %( Total time (read, parse and convert): #{sprintf '%05.5f', read_parse_convert.to_f}) end |
#read ⇒ Object
22 23 24 |
# File 'lib/asciidoctor/timings.rb', line 22 def read time :read end |
#read_parse ⇒ Object
30 31 32 |
# File 'lib/asciidoctor/timings.rb', line 30 def read_parse time :read, :parse end |
#read_parse_convert ⇒ Object
38 39 40 |
# File 'lib/asciidoctor/timings.rb', line 38 def read_parse_convert time :read, :parse, :convert end |
#record(key) ⇒ Object
13 14 15 |
# File 'lib/asciidoctor/timings.rb', line 13 def record key @log[key] = (now - (@timers.delete key)) end |
#start(key) ⇒ Object
9 10 11 |
# File 'lib/asciidoctor/timings.rb', line 9 def start key @timers[key] = now end |
#time(*keys) ⇒ Object
17 18 19 20 |
# File 'lib/asciidoctor/timings.rb', line 17 def time *keys time = keys.reduce(0) {|sum, key| sum + (@log[key] || 0) } time > 0 ? time : nil end |
#total ⇒ Object
46 47 48 |
# File 'lib/asciidoctor/timings.rb', line 46 def total time :read, :parse, :convert, :write end |
#write ⇒ Object
42 43 44 |
# File 'lib/asciidoctor/timings.rb', line 42 def write time :write end |