Sha256: 96588c569b1a4dd55cd57482912e7a2047aa48959e5b5fb39f986e826fd49704

Contents?: true

Size: 600 Bytes

Versions: 5

Compression:

Stored size: 600 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('WBench.resourceURLs()')).map do |url|
          Addressable::URI.parse(url).host
        end.compact.uniq
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wbench-0.3.7 lib/wbench/timings/latency.rb
wbench-0.3.6 lib/wbench/timings/latency.rb
wbench-0.3.5 lib/wbench/timings/latency.rb
wbench-0.3.4 lib/wbench/timings/latency.rb
wbench-0.3.3 lib/wbench/timings/latency.rb