Sha256: eb6ba88d1d112b8e6df47e56c63118f6f23c2241e09cb719e80345bd4fddf69e

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Asciidoctor
  class Timings
    def initialize
      @log = {}
      @timers = {}
    end

    def start key
      @timers[key] = ::Time.now
    end

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

    def read_parse
      (time = (@log[:read] || 0) + (@log[:parse] || 0)) > 0 ? time : nil
    end

    def convert
      @log[:convert] || 0
    end

    def read_parse_convert
      (time = (@log[:read] || 0) + (@log[:parse] || 0) + (@log[:convert] || 0)) > 0 ? time : nil
    end

    def total
      (time = (@log[:read] || 0) + (@log[:parse] || 0) + (@log[:convert] || 0) + (@log[:write] || 0)) > 0 ? time : nil
    end

    def print_report to = $stdout, subject = nil
      to.puts %(Input file: #{subject}) if subject
      to.puts %(  Time to read and parse source: #{'%05.5f' % read_parse.to_i})
      to.puts %(  Time to convert document: #{'%05.5f' % convert.to_i})
      to.puts %(  Total time (read, parse and convert): #{'%05.5f' % read_parse_convert.to_i})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
asciidoctor-1.5.1 lib/asciidoctor/timings.rb
asciidoctor-1.5.0 lib/asciidoctor/timings.rb