Class: Asciidoctor::Timings

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

Instance Method Summary collapse

Constructor Details

#initializeTimings

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

#convertObject



34
35
36
# File 'lib/asciidoctor/timings.rb', line 34

def convert
  time :convert
end

#parseObject



26
27
28
# File 'lib/asciidoctor/timings.rb', line 26

def parse
  time :parse
end


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

#readObject



22
23
24
# File 'lib/asciidoctor/timings.rb', line 22

def read
  time :read
end

#read_parseObject



30
31
32
# File 'lib/asciidoctor/timings.rb', line 30

def read_parse
  time :read, :parse
end

#read_parse_convertObject



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

#totalObject



46
47
48
# File 'lib/asciidoctor/timings.rb', line 46

def total
  time :read, :parse, :convert, :write
end

#writeObject



42
43
44
# File 'lib/asciidoctor/timings.rb', line 42

def write
  time :write
end