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.



5
6
7
8
# File 'lib/asciidoctor/timings.rb', line 5

def initialize
  @log = {}
  @timers = {}
end

Instance Method Details

#convertObject



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

def convert
  time :convert
end

#parseObject



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

def parse
  time :parse
end


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

#readObject



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

def read
  time :read
end

#read_parseObject



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

def read_parse
  time :read, :parse
end

#read_parse_convertObject



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

#totalObject



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

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

#writeObject



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

def write
  time :write
end