Sha256: 6e1fa9556778eeb4cd3caeb8ec3b9d6a43fcc09b03d60917984ee4c1506f365a

Contents?: true

Size: 671 Bytes

Versions: 8

Compression:

Stored size: 671 Bytes

Contents

java_import 'java.lang.System' if RUBY_PLATFORM == 'java'

module Timing
  def self.start
    TimingContext.new
  end

  class TimingContext
    def initialize
      @jruby = RUBY_PLATFORM == 'java'
      reset!
    end

    def reset!
      @start = @last_tick = now
    end

    def tick
      rt = runtime_since(@last_tick)
      @last_tick = now
      rt
    end

    def stop
      rt = runtime_since(@start)
      reset!
      rt
    end

    private

    def now
      return System.nano_time if @jruby
      return Time.now.to_f
    end

    def runtime_since(start)
      rt = now - start
      rt = rt.to_f / 1_000_000_000 if @jruby
      rt
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
liquid-ext-1.2.6 lib/liquid/timing.rb
liquid-ext-1.2.5 lib/liquid/timing.rb
liquid-ext-1.2.4 lib/liquid/timing.rb
liquid-ext-1.2.2 lib/liquid/timing.rb
liquid-ext-1.2.1 lib/liquid/timing.rb
liquid-ext-1.2.0 lib/liquid/timing.rb
liquid-ext-1.1.1 lib/liquid/timing.rb
liquid-ext-1.1.0 lib/liquid/timing.rb