class Asciidoctor::Timings

def convert

def convert
  time :convert
end

def initialize

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

def now

def now
  ::Process.clock_gettime CLOCK_ID
end

def now

def now
  ::Time.now
end

def parse

def parse
  time :parse
end

def print_report to = $stdout, subject = nil

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

def read

def read
  time :read
end

def read_parse

def read_parse
  time :read, :parse
end

def read_parse_convert

def read_parse_convert
  time :read, :parse, :convert
end

def record key

def record key
  @log[key] = (now - (@timers.delete key))
end

def start key

def start key
  @timers[key] = now
end

def time *keys

def time *keys
  time = keys.reduce(0) {|sum, key| sum + (@log[key] || 0) }
  time > 0 ? time : nil
end

def total

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

def write

def write
  time :write
end