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.
5 6 7 8 |
# File 'lib/asciidoctor/timings.rb', line 5 def initialize @log = {} @timers = {} end |
Instance Method Details
#convert ⇒ Object
35 36 37 |
# File 'lib/asciidoctor/timings.rb', line 35 def convert time :convert end |
#parse ⇒ Object
27 28 29 |
# File 'lib/asciidoctor/timings.rb', line 27 def parse time :parse end |
#print_report(to = $stdout, subject = nil) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/asciidoctor/timings.rb', line 51 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
23 24 25 |
# File 'lib/asciidoctor/timings.rb', line 23 def read time :read end |
#read_parse ⇒ Object
31 32 33 |
# File 'lib/asciidoctor/timings.rb', line 31 def read_parse time :read, :parse end |
#read_parse_convert ⇒ Object
39 40 41 |
# File 'lib/asciidoctor/timings.rb', line 39 def read_parse_convert time :read, :parse, :convert end |
#record(key) ⇒ Object
14 15 16 |
# File 'lib/asciidoctor/timings.rb', line 14 def record key @log[key] = (now - (@timers.delete key)) end |
#start(key) ⇒ Object
10 11 12 |
# File 'lib/asciidoctor/timings.rb', line 10 def start key @timers[key] = now end |
#time(*keys) ⇒ Object
18 19 20 21 |
# File 'lib/asciidoctor/timings.rb', line 18 def time *keys time = keys.reduce(0) {|sum, key| sum + (@log[key] || 0) } time > 0 ? time : nil end |
#total ⇒ Object
47 48 49 |
# File 'lib/asciidoctor/timings.rb', line 47 def total time :read, :parse, :convert, :write end |
#write ⇒ Object
43 44 45 |
# File 'lib/asciidoctor/timings.rb', line 43 def write time :write end |