wbench 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dfb44fa9da6a36574ee13ee7b541a0beee68cbf
4
- data.tar.gz: def12740e6a51ddf81d71d8479d1acb150d2fe17
3
+ metadata.gz: 3a99e98258f2293683471f454c7e0f9e7dbbfc9b
4
+ data.tar.gz: 78a484762385e2926fa49b47f0143e10bece9fa3
5
5
  SHA512:
6
- metadata.gz: 0ebecb25fe5ae425c7effb70ea8b7fc2c71a5fde0c0df1865664a81201ef997e1b9bbd0386745bcf3dc6654ee1195df267f15fef5e7d7e94bde9265cc9efac8a
7
- data.tar.gz: b90b6da372c793a2a28db28f12341d6b5625b0161f2c661133afa3729e9482e2d5b6a83e26b181b90bbfdf88c020623143c76f56869e9f6c572b715e2ac255f8
6
+ metadata.gz: 1da1f3692c3f18b4bb41313db19107c56553dae54c3dc0685d1be3e2f5893f8c52b2e991c0e923da6f8bf1d8caffe40b8354ee1f56f397b946f37316b72b96ea
7
+ data.tar.gz: 08ae38bf3f64536e2b2abdca96afe27b5516fc5322ab1a13321043db5c1936597563f2a22e0da00cc7867fbed5c7cc9bc13efcb2ed28cf9738a60dfd21580b2e
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --require spec_helper
1
2
  --color
2
3
  --format progress
data/README.md CHANGED
@@ -74,22 +74,34 @@ results.app_server # =>
74
74
  [25, 24, 24]
75
75
 
76
76
  results.browser # =>
77
- {"navigationStart"=>[0, 0, 0], "fetchStart"=>[0, 0, 0],
78
- "domainLookupStart"=>[0, 0, 0], "domainLookupEnd"=>[0, 0, 0],
79
- "connectStart"=>[12, 12, 11], "connectEnd"=>[609, 612, 599],
80
- "secureConnectionStart"=>[197, 195, 194], "requestStart"=>[609, 612, 599],
81
- "responseStart"=>[829, 858, 821], "responseEnd"=>[1025, 1053, 1013],
82
- "domLoading"=>[1028, 1055, 1016], "domInteractive"=>[1549, 1183, 1136],
83
- "domContentLoadedEventStart"=>[1549, 1183, 1136],
84
- "domContentLoadedEventEnd"=>[1549, 1184, 1137], "domComplete"=>[2042, 1712,
85
- 1663], "loadEventStart"=>[2042, 1712, 1663], "loadEventEnd"=>[2057, 1730,
86
- 1680]}
77
+ {
78
+ "navigationStart" => [0, 0, 0],
79
+ "fetchStart" => [0, 0, 0],
80
+ "domainLookupStart" => [0, 0, 0],
81
+ "domainLookupEnd" => [0, 0, 0],
82
+ "connectStart" => [12, 12, 11],
83
+ "connectEnd" => [609, 612, 599],
84
+ "secureConnectionStart" => [197, 195, 194],
85
+ "requestStart" => [609, 612, 599],
86
+ "responseStart" => [829, 858, 821],
87
+ "responseEnd" => [1025, 1053, 1013],
88
+ "domLoading" => [1028, 1055, 1016],
89
+ "domInteractive" => [1549, 1183, 1136],
90
+ "domContentLoadedEventStart" => [1549, 1183, 1136],
91
+ "domContentLoadedEventEnd" => [1549, 1184, 1137],
92
+ "domComplete" => [2042, 1712, 1663],
93
+ "loadEventStart" => [2042, 1712, 1663],
94
+ "loadEventEnd" => [2057, 1730, 1680]
95
+ }
87
96
 
88
97
  results.latency # =>
89
- {"a.desktopprassets.com"=>[352, 15, 15],
90
- "beacon-1.newrelic.com"=>[587, 235, 248],
91
- "d1ros97qkrwjf5.cloudfront.net"=>[368, 14, 14],
92
- "ssl.google-analytics.com"=>[497, 14, 14], "www.desktoppr.co"=>[191, 210, 203]}
98
+ {
99
+ "a.desktopprassets.com" => [352, 15, 15],
100
+ "beacon-1.newrelic.com" => [587, 235, 248],
101
+ "d1ros97qkrwjf5.cloudfront.net" => [368, 14, 14],
102
+ "ssl.google-analytics.com" => [497, 14, 14],
103
+ "www.desktoppr.co" => [191, 210, 203]
104
+ }
93
105
  ```
94
106
 
95
107
  ### Benchmarking authenticated pages
data/bin/wbench CHANGED
@@ -25,9 +25,16 @@ options = {}.tap do |options|
25
25
  options[:user_agent] = user_agent
26
26
  end
27
27
 
28
+ opts.on("-c", "--no-color", "Disable color output") do
29
+ options[:color_output] = false
30
+ end
28
31
  end.parse!
29
32
  end
30
33
 
34
+ if options.has_key?(:color_output)
35
+ WBench.color_output = options.delete(:color_output)
36
+ end
37
+
31
38
  if url = ARGV[0]
32
39
  puts WBench::Benchmark.run(url, options)
33
40
  else
@@ -13,6 +13,7 @@ require 'wbench/timings/browser'
13
13
  require 'wbench/timings/latency'
14
14
  require 'wbench/benchmark'
15
15
  require 'wbench/browser'
16
+ require 'wbench/colored_string'
16
17
  require 'wbench/selenium_driver'
17
18
  require 'wbench/results'
18
19
  require 'wbench/results_formatter'
@@ -27,4 +28,10 @@ module WBench
27
28
  CAPYBARA_TIMEOUT = 60
28
29
  DEFAULT_LOOPS = 10
29
30
  DEFAULT_BROWSER = :chrome
31
+
32
+ class << self
33
+ attr_accessor :color_output
34
+ end
35
+
36
+ self.color_output = true
30
37
  end
@@ -0,0 +1,11 @@
1
+ module WBench
2
+ class ColoredString < String
3
+ def initialize(string, color)
4
+ if WBench.color_output
5
+ super(string.colorize(color))
6
+ else
7
+ super(string)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -49,15 +49,15 @@ module WBench
49
49
  end
50
50
 
51
51
  def latency_heading_s
52
- "Host latency:\n".colorize(:yellow)
52
+ ColoredString.new("Host latency:\n", :yellow)
53
53
  end
54
54
 
55
55
  def browser_heading_s
56
- "Browser performance:\n".colorize(:yellow)
56
+ ColoredString.new("Browser performance:\n", :yellow)
57
57
  end
58
58
 
59
59
  def app_heading_s
60
- "Server performance:\n".colorize(:yellow)
60
+ ColoredString.new("Server performance:\n", :yellow)
61
61
  end
62
62
  end
63
63
  end
@@ -20,23 +20,23 @@ module WBench
20
20
  end
21
21
 
22
22
  def no_result_s
23
- 'Unable to be recorded'.center(40).colorize(:light_red)
23
+ ColoredString.new('Unable to be recorded'.center(40), :light_red)
24
24
  end
25
25
 
26
26
  def fastest_s
27
- "#{@stats.min}ms".ljust(10).colorize(:green)
27
+ ColoredString.new("#{@stats.min}ms".ljust(10), :green)
28
28
  end
29
29
 
30
30
  def slowest_s
31
- "#{@stats.max}ms".ljust(10).colorize(:red)
31
+ ColoredString.new("#{@stats.max}ms".ljust(10), :red)
32
32
  end
33
33
 
34
34
  def median_s
35
- "#{@stats.median}ms".ljust(10).colorize(:blue)
35
+ ColoredString.new("#{@stats.median}ms".ljust(10), :blue)
36
36
  end
37
37
 
38
38
  def std_dev_s
39
- "#{@stats.std_dev.to_i}ms".ljust(10).colorize(:yellow)
39
+ ColoredString.new("#{@stats.std_dev.to_i}ms".ljust(10), :yellow)
40
40
  end
41
41
  end
42
42
  end
@@ -2,20 +2,32 @@ module WBench
2
2
  module Timings
3
3
  class AppServer
4
4
  def initialize(browser)
5
- uri = Addressable::URI.parse(browser.url)
6
- @http = Net::HTTP.new(uri.host, uri.inferred_port)
7
- @http.use_ssl = uri.scheme == 'https'
8
-
9
- @request = Net::HTTP::Get.new(uri.request_uri)
5
+ @browser = browser
10
6
  end
11
7
 
12
8
  def result
13
- response = @http.request(@request)
9
+ response = http.request(request)
14
10
 
15
11
  unless response.header['x-runtime'].nil?
16
- (response.header['x-runtime'].to_f*1000).to_i
12
+ (response.header['x-runtime'].to_f * 1000).to_i
17
13
  end
18
14
  end
15
+
16
+ private
17
+
18
+ def uri
19
+ Addressable::URI.parse(@browser.url)
20
+ end
21
+
22
+ def http
23
+ Net::HTTP.new(uri.host, uri.inferred_port).tap do |http|
24
+ http.use_ssl = uri.scheme == 'https'
25
+ end
26
+ end
27
+
28
+ def request
29
+ Net::HTTP::Get.new(uri.request_uri)
30
+ end
19
31
  end
20
32
  end
21
33
  end
@@ -6,10 +6,14 @@ module WBench
6
6
  end
7
7
 
8
8
  def result
9
- timing_json = @browser.evaluate_script('window.performance.timing')
10
-
11
9
  TimingHash.new(timing_json)
12
10
  end
11
+
12
+ private
13
+
14
+ def timing_json
15
+ @browser.evaluate_script('window.performance.timing')
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -6,20 +6,21 @@ module WBench
6
6
  end
7
7
 
8
8
  def result
9
- Hash[domains.map { |domain| [domain, latency_for(domain) ] }.sort]
9
+ Hash[hosts.map { |host| [host.join(":"), latency_for(*host) ] }.sort]
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def latency_for(domain)
15
- (::Benchmark.measure { TCPSocket.new(domain, 80) }.real * 1000).to_i
14
+ def latency_for(hostname, port)
15
+ (::Benchmark.measure { TCPSocket.new(hostname, port) }.real * 1000).to_i
16
16
  rescue SocketError
17
17
  nil
18
18
  end
19
19
 
20
- def domains
21
- @domains ||= JSON.parse(@browser.evaluate_script('WBench.resourceURLs()')).map do |url|
22
- Addressable::URI.parse(url).host
20
+ def hosts
21
+ @hosts ||= JSON.parse(@browser.evaluate_script('WBench.resourceURLs()')).map do |url|
22
+ u = Addressable::URI.parse(url)
23
+ [u.host, u.inferred_port]
23
24
  end.compact.uniq
24
25
  end
25
26
  end
@@ -1,3 +1,3 @@
1
1
  module WBench
2
- VERSION = '0.3.7'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  require File.expand_path(File.dirname(__FILE__)) + '/../support/test_sites'
4
2
 
5
3
  describe 'wbench' do
@@ -0,0 +1,64 @@
1
+ describe WBench::Timings::Latency do
2
+ subject(:latency) { described_class.new(browser) }
3
+ let(:browser) { double 'browser' }
4
+ let(:resource_urls) do
5
+ JSON.dump([
6
+ "http://3.example.com/path",
7
+ "https://1.example.com/path",
8
+ "http://2.example.com:3000/path",
9
+ ])
10
+ end
11
+
12
+ before do
13
+ allow(browser).to receive(:evaluate_script).with('WBench.resourceURLs()') { resource_urls }
14
+ allow(::Benchmark).to receive(:measure).and_yield.and_return(30, 10, 20)
15
+ end
16
+
17
+ describe "#result" do
18
+ shared_examples_for "result" do
19
+ it "measures latency for every host" do
20
+ expect(::Benchmark).to receive(:measure).and_yield.and_return(30, 10, 20)
21
+ expect(::TCPSocket).to receive(:new).with("1.example.com", 443)
22
+ expect(::TCPSocket).to receive(:new).with("2.example.com", 3000)
23
+ expect(::TCPSocket).to receive(:new).with("3.example.com", 80)
24
+ latency.result
25
+ end
26
+
27
+ it "returns a hash of the measurement results, sorted by hostname" do
28
+ expect(latency.result).to eq expected_result
29
+ end
30
+ end
31
+
32
+ context "when no SocketError" do
33
+ before do
34
+ allow(::TCPSocket).to receive(:new)
35
+ end
36
+
37
+ let(:expected_result) do
38
+ {
39
+ "1.example.com:443" => 10000,
40
+ "2.example.com:3000" => 20000,
41
+ "3.example.com:80" => 30000,
42
+ }
43
+ end
44
+
45
+ it_behaves_like "result"
46
+ end
47
+
48
+ context "on SocketError" do
49
+ before do
50
+ allow(TCPSocket).to receive(:new).and_raise(SocketError.new)
51
+ end
52
+
53
+ let(:expected_result) do
54
+ {
55
+ "1.example.com:443" => nil,
56
+ "2.example.com:3000" => nil,
57
+ "3.example.com:80" => nil,
58
+ }
59
+ end
60
+
61
+ it_behaves_like "result"
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe WBench::Stats do
4
2
  describe '#median' do
5
3
  context 'when there are an odd number of results' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe WBench::TimingHash do
4
2
  describe '#new' do
5
3
  let(:timings) { { :end => 20, :middle => 15, :start => 10, :nope => 0 } }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe WBench::Titleizer do
4
2
  describe '#to_s' do
5
3
  subject { described_class.new('dom loading time') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wbench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Visic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -89,6 +89,7 @@ files:
89
89
  - lib/wbench.rb
90
90
  - lib/wbench/benchmark.rb
91
91
  - lib/wbench/browser.rb
92
+ - lib/wbench/colored_string.rb
92
93
  - lib/wbench/results.rb
93
94
  - lib/wbench/results_formatter.rb
94
95
  - lib/wbench/row_formatter.rb
@@ -103,6 +104,7 @@ files:
103
104
  - spec/spec_helper.rb
104
105
  - spec/support/test_sites.rb
105
106
  - spec/wbench/integration_spec.rb
107
+ - spec/wbench/latency_spec.rb
106
108
  - spec/wbench/stats_spec.rb
107
109
  - spec/wbench/timing_hash_spec.rb
108
110
  - spec/wbench/titleizer_spec.rb
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  version: '0'
128
130
  requirements: []
129
131
  rubyforge_project:
130
- rubygems_version: 2.0.3
132
+ rubygems_version: 2.0.6
131
133
  signing_key:
132
134
  specification_version: 4
133
135
  summary: Benchmark website loading times
@@ -135,6 +137,7 @@ test_files:
135
137
  - spec/spec_helper.rb
136
138
  - spec/support/test_sites.rb
137
139
  - spec/wbench/integration_spec.rb
140
+ - spec/wbench/latency_spec.rb
138
141
  - spec/wbench/stats_spec.rb
139
142
  - spec/wbench/timing_hash_spec.rb
140
143
  - spec/wbench/titleizer_spec.rb