Sha256: 4f3a11eedadf21423a21d694286f82e509c323cdd8ae20a338cad49d9c3ef017

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true
require 'cucumber/core/test/result'

module Cucumber
  module Core
    module Test
      class Timer
        def start
          @start_time = time_in_nanoseconds
          self
        end

        def duration
          Result::Duration.new(nsec)
        end

        def nsec
          time_in_nanoseconds - @start_time
        end

        def sec
          nsec / (10**9.0)
        end

        private

        def time_in_nanoseconds
          MonotonicTime.time_in_nanoseconds
        end

        module MonotonicTime
          module_function

          if defined?(Process::CLOCK_MONOTONIC)
            def time_in_nanoseconds
              Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
            end
          elsif (defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby') == 'jruby'
            def time_in_nanoseconds
              java.lang.System.nanoTime()
            end
          else
            def time_in_nanoseconds
              t = Time.now
              (t.to_i * (10**9)) + t.nsec
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-core-12.0.0/lib/cucumber/core/test/timer.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-core-11.1.0/lib/cucumber/core/test/timer.rb
cucumber-core-12.0.0 lib/cucumber/core/test/timer.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/test/timer.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/test/timer.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/test/timer.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/test/timer.rb
cucumber-core-11.1.0 lib/cucumber/core/test/timer.rb
cucumber-core-11.0.0 lib/cucumber/core/test/timer.rb
cucumber-core-10.1.1 lib/cucumber/core/test/timer.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-core-10.1.0/lib/cucumber/core/test/timer.rb
cucumber-core-10.1.0 lib/cucumber/core/test/timer.rb