Sha256: 48b5dac52043ba30582c477ea7c8862dfb408114075d275b68c422639c40fc57

Contents?: true

Size: 590 Bytes

Versions: 2

Compression:

Stored size: 590 Bytes

Contents

module WBench
  module Timings
    class Latency
      def initialize(browser)
        @browser = browser
      end

      def result
        Hash[domains.map { |domain| [domain, latency_for(domain) ] }.sort]
      end

      private

      def latency_for(domain)
        (::Benchmark.measure { TCPSocket.new(domain, 80) }.real * 1000).to_i
      rescue SocketError
        nil
      end

      def domains
        @domains ||= JSON.parse(@browser.evaluate_script('JSON.stringify(resourceURLs())')).map do |url|
          URI(url).host
        end.compact.uniq
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wbench-0.2.2 lib/wbench/timings/latency.rb
wbench-0.2.1 lib/wbench/timings/latency.rb