From da58f91fe2613dbac277c4bad857a3d2220e5d9b Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Sun, 3 Feb 2013 20:14:21 +1100 Subject: [PATCH] Initial commit, works, no tests, like a cowboy. --- .gitignore | 17 + .rspec | 2 + .rvmrc | 1 + Gemfile | 8 + LICENSE.txt | 22 + README.md | 29 ++ Rakefile | 1 + bin/wbench | 11 + chromedriver.log | 632 +++++++++++++++++++++++ lib/website_benchmarker.rb | 8 + lib/website_benchmarker/results.rb | 36 ++ lib/website_benchmarker/row_formatter.rb | 35 ++ lib/website_benchmarker/test.rb | 29 ++ lib/website_benchmarker/timing_hash.rb | 16 + lib/website_benchmarker/version.rb | 3 + spec/spec_helper.rb | 7 + spec/timings_spec.rb | 13 + website_benchmarker.gemspec | 19 + 18 files changed, 889 insertions(+) create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 .rvmrc create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/wbench create mode 100644 chromedriver.log create mode 100644 lib/website_benchmarker.rb create mode 100644 lib/website_benchmarker/results.rb create mode 100644 lib/website_benchmarker/row_formatter.rb create mode 100644 lib/website_benchmarker/test.rb create mode 100644 lib/website_benchmarker/timing_hash.rb create mode 100644 lib/website_benchmarker/version.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/timings_spec.rb create mode 100644 website_benchmarker.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5f16476 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format progress diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..f890983 --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm use @website_benchmarker --create diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7ade12a --- /dev/null +++ b/Gemfile @@ -0,0 +1,8 @@ +source :rubygems + +gemspec + +group :test do + gem 'rspec' + gem 'capybara' +end diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b552b12 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Mario Visic + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..52fd323 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# WebsiteBenchmarker + +TODO: Write a gem description + +## Installation + +Add this line to your application's Gemfile: + + gem 'website_benchmarker' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install website_benchmarker + +## Usage + +TODO: Write usage instructions here + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..c702cfc --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require 'bundler/gem_tasks' diff --git a/bin/wbench b/bin/wbench new file mode 100755 index 0000000..67e98ae --- /dev/null +++ b/bin/wbench @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) +$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) +require 'website_benchmarker' + +if url = ARGV[0] + WebsiteBenchmarker::Test.run(url) +else + abort 'Please provide a URL to benchmark' +end diff --git a/chromedriver.log b/chromedriver.log new file mode 100644 index 0000000..384d6bc --- /dev/null +++ b/chromedriver.log @@ -0,0 +1,632 @@ +[0.001][INFO]: ChromeDriver 23.0.1240.0 /usr/local/bin/chromedriver +[0.237][FINE]: Initializing session with capabilities { + "browserName": "chrome", + "chrome.detach": true, + "chromeOptions": { + "detach": true + }, + "cssSelectorsEnabled": true, + "javascriptEnabled": true, + "nativeEvents": false, + "platform": "ANY", + "rotatable": false, + "takesScreenshot": false, + "version": "" +} + +[0.237][INFO]: Using named testing interface +[0.696][INFO]: Connected to Chrome successfully. Version: 24.0.1312.57 +[0.700][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e) +[0.700][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + "acceptSslCerts": false, + "applicationCacheEnabled": false, + "browserConnectionEnabled": false, + "browserName": "chrome", + "chrome.chromedriverVersion": "23.0.1240.0", + "chrome.nativeEvents": false, + "cssSelectorsEnabled": true, + "databaseEnabled": false, + "handlesAlerts": true, + "javascriptEnabled": true, + "locationContextEnabled": false, + "nativeEvents": true, + "platform": "mac", + "rotatable": false, + "takesScreenshot": true, + "version": "24.0.1312.57", + "webStorageEnabled": true + } +} + +[0.701][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[0.702][FINER]: Waiting for all views to stop loading... +[0.713][FINER]: Done waiting for all views to stop loading +[1.233][FINER]: Waiting for all views to stop loading... +[1.233][FINER]: Done waiting for all views to stop loading +[1.233][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[1.254][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[1.254][FINER]: Waiting for all views to stop loading... +[1.254][FINER]: Done waiting for all views to stop loading +[1.410][FINER]: Waiting for all views to stop loading... +[1.410][FINER]: Done waiting for all views to stop loading +[1.411][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882790466" + } ] +} + +[1.670][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[1.670][FINER]: Waiting for all views to stop loading... +[1.671][FINER]: Done waiting for all views to stop loading +[1.675][FINER]: Waiting for all views to stop loading... +[1.676][FINER]: Done waiting for all views to stop loading +[1.676][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882790581,\"loadEventStart\":1359882790579,\"domComplete\":1359882790579,\"domCont..." +} + +[1.677][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[1.677][FINER]: Waiting for all views to stop loading... +[1.677][FINER]: Done waiting for all views to stop loading +[1.681][FINER]: Waiting for all views to stop loading... +[1.681][FINER]: Done waiting for all views to stop loading +[1.681][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[1.682][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[1.682][FINER]: Waiting for all views to stop loading... +[1.682][FINER]: Done waiting for all views to stop loading +[1.933][FINER]: Waiting for all views to stop loading... +[1.938][FINER]: Done waiting for all views to stop loading +[1.938][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[1.939][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[1.939][FINER]: Waiting for all views to stop loading... +[1.939][FINER]: Done waiting for all views to stop loading +[2.692][FINER]: Waiting for all views to stop loading... +[2.716][FINER]: Done waiting for all views to stop loading +[2.716][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[2.718][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[2.718][FINER]: Waiting for all views to stop loading... +[2.725][FINER]: Done waiting for all views to stop loading +[2.735][FINER]: Waiting for all views to stop loading... +[2.735][FINER]: Done waiting for all views to stop loading +[2.735][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882791790" + } ] +} + +[2.988][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[2.988][FINER]: Waiting for all views to stop loading... +[2.989][FINER]: Done waiting for all views to stop loading +[2.994][FINER]: Waiting for all views to stop loading... +[2.994][FINER]: Done waiting for all views to stop loading +[2.994][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882791763,\"loadEventStart\":1359882791761,\"domComplete\":1359882791761,\"domCont..." +} + +[2.995][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[2.995][FINER]: Waiting for all views to stop loading... +[2.995][FINER]: Done waiting for all views to stop loading +[2.998][FINER]: Waiting for all views to stop loading... +[2.998][FINER]: Done waiting for all views to stop loading +[2.998][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[2.999][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[2.999][FINER]: Waiting for all views to stop loading... +[2.999][FINER]: Done waiting for all views to stop loading +[3.185][FINER]: Waiting for all views to stop loading... +[3.198][FINER]: Done waiting for all views to stop loading +[3.198][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[3.199][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[3.199][FINER]: Waiting for all views to stop loading... +[3.199][FINER]: Done waiting for all views to stop loading +[4.062][FINER]: Waiting for all views to stop loading... +[4.080][FINER]: Done waiting for all views to stop loading +[4.080][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[4.081][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[4.081][FINER]: Waiting for all views to stop loading... +[4.081][FINER]: Done waiting for all views to stop loading +[4.090][FINER]: Waiting for all views to stop loading... +[4.091][FINER]: Done waiting for all views to stop loading +[4.091][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882793146" + } ] +} + +[4.344][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[4.344][FINER]: Waiting for all views to stop loading... +[4.344][FINER]: Done waiting for all views to stop loading +[4.349][FINER]: Waiting for all views to stop loading... +[4.349][FINER]: Done waiting for all views to stop loading +[4.349][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882793119,\"loadEventStart\":1359882793117,\"domComplete\":1359882793117,\"domCont..." +} + +[4.350][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[4.350][FINER]: Waiting for all views to stop loading... +[4.350][FINER]: Done waiting for all views to stop loading +[4.353][FINER]: Waiting for all views to stop loading... +[4.353][FINER]: Done waiting for all views to stop loading +[4.353][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[4.354][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[4.354][FINER]: Waiting for all views to stop loading... +[4.354][FINER]: Done waiting for all views to stop loading +[4.543][FINER]: Waiting for all views to stop loading... +[4.555][FINER]: Done waiting for all views to stop loading +[4.555][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[4.555][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[4.555][FINER]: Waiting for all views to stop loading... +[4.556][FINER]: Done waiting for all views to stop loading +[5.320][FINER]: Waiting for all views to stop loading... +[5.320][FINER]: Done waiting for all views to stop loading +[5.320][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[5.321][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[5.321][FINER]: Waiting for all views to stop loading... +[5.322][FINER]: Done waiting for all views to stop loading +[5.352][FINER]: Waiting for all views to stop loading... +[5.353][FINER]: Done waiting for all views to stop loading +[5.353][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882794395" + } ] +} + +[5.605][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[5.605][FINER]: Waiting for all views to stop loading... +[5.606][FINER]: Done waiting for all views to stop loading +[5.611][FINER]: Waiting for all views to stop loading... +[5.611][FINER]: Done waiting for all views to stop loading +[5.611][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882794398,\"loadEventStart\":1359882794396,\"domComplete\":1359882794396,\"domCont..." +} + +[5.612][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[5.612][FINER]: Waiting for all views to stop loading... +[5.612][FINER]: Done waiting for all views to stop loading +[5.615][FINER]: Waiting for all views to stop loading... +[5.615][FINER]: Done waiting for all views to stop loading +[5.615][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[5.616][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[5.616][FINER]: Waiting for all views to stop loading... +[5.616][FINER]: Done waiting for all views to stop loading +[5.799][FINER]: Waiting for all views to stop loading... +[5.814][FINER]: Done waiting for all views to stop loading +[5.814][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[5.815][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[5.815][FINER]: Waiting for all views to stop loading... +[5.823][FINER]: Done waiting for all views to stop loading +[6.581][FINER]: Waiting for all views to stop loading... +[6.592][FINER]: Done waiting for all views to stop loading +[6.592][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[6.593][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[6.593][FINER]: Waiting for all views to stop loading... +[6.594][FINER]: Done waiting for all views to stop loading +[6.714][FINER]: Waiting for all views to stop loading... +[6.714][FINER]: Done waiting for all views to stop loading +[6.714][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882795769" + } ] +} + +[6.966][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[6.966][FINER]: Waiting for all views to stop loading... +[6.966][FINER]: Done waiting for all views to stop loading +[6.971][FINER]: Waiting for all views to stop loading... +[6.971][FINER]: Done waiting for all views to stop loading +[6.971][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882795797,\"loadEventStart\":1359882795786,\"domComplete\":1359882795786,\"domCont..." +} + +[6.972][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[6.972][FINER]: Waiting for all views to stop loading... +[6.972][FINER]: Done waiting for all views to stop loading +[6.975][FINER]: Waiting for all views to stop loading... +[6.975][FINER]: Done waiting for all views to stop loading +[6.975][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[6.976][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[6.976][FINER]: Waiting for all views to stop loading... +[6.976][FINER]: Done waiting for all views to stop loading +[7.158][FINER]: Waiting for all views to stop loading... +[7.173][FINER]: Done waiting for all views to stop loading +[7.174][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[7.174][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[7.174][FINER]: Waiting for all views to stop loading... +[7.175][FINER]: Done waiting for all views to stop loading +[7.932][FINER]: Waiting for all views to stop loading... +[7.954][FINER]: Done waiting for all views to stop loading +[7.954][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[7.955][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[7.955][FINER]: Waiting for all views to stop loading... +[7.965][FINER]: Done waiting for all views to stop loading +[7.974][FINER]: Waiting for all views to stop loading... +[7.974][FINER]: Done waiting for all views to stop loading +[7.974][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882797030" + } ] +} + +[8.227][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[8.227][FINER]: Waiting for all views to stop loading... +[8.228][FINER]: Done waiting for all views to stop loading +[8.233][FINER]: Waiting for all views to stop loading... +[8.233][FINER]: Done waiting for all views to stop loading +[8.233][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882797002,\"loadEventStart\":1359882797000,\"domComplete\":1359882797000,\"domCont..." +} + +[8.234][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[8.234][FINER]: Waiting for all views to stop loading... +[8.234][FINER]: Done waiting for all views to stop loading +[8.237][FINER]: Waiting for all views to stop loading... +[8.237][FINER]: Done waiting for all views to stop loading +[8.237][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[8.238][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[8.238][FINER]: Waiting for all views to stop loading... +[8.238][FINER]: Done waiting for all views to stop loading +[8.483][FINER]: Waiting for all views to stop loading... +[8.487][FINER]: Done waiting for all views to stop loading +[8.487][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[8.488][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[8.488][FINER]: Waiting for all views to stop loading... +[8.488][FINER]: Done waiting for all views to stop loading +[9.256][FINER]: Waiting for all views to stop loading... +[9.256][FINER]: Done waiting for all views to stop loading +[9.256][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[9.257][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[9.257][FINER]: Waiting for all views to stop loading... +[9.258][FINER]: Done waiting for all views to stop loading +[9.288][FINER]: Waiting for all views to stop loading... +[9.288][FINER]: Done waiting for all views to stop loading +[9.288][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882798335" + } ] +} + +[9.541][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[9.541][FINER]: Waiting for all views to stop loading... +[9.541][FINER]: Done waiting for all views to stop loading +[9.546][FINER]: Waiting for all views to stop loading... +[9.546][FINER]: Done waiting for all views to stop loading +[9.546][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882798338,\"loadEventStart\":1359882798336,\"domComplete\":1359882798336,\"domCont..." +} + +[9.546][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) +[9.546][FINER]: Waiting for all views to stop loading... +[9.547][FINER]: Done waiting for all views to stop loading +[9.550][FINER]: Waiting for all views to stop loading... +[9.550][FINER]: Done waiting for all views to stop loading +[9.550][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/cookie) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[9.551][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "about:blank" +} + +[9.551][FINER]: Waiting for all views to stop loading... +[9.551][FINER]: Done waiting for all views to stop loading +[9.734][FINER]: Waiting for all views to stop loading... +[9.751][FINER]: Done waiting for all views to stop loading +[9.752][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[9.752][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with params { + "url": "http://www.google.com" +} + +[9.752][FINER]: Waiting for all views to stop loading... +[9.753][FINER]: Done waiting for all views to stop loading +[10.568][FINER]: Waiting for all views to stop loading... +[10.596][FINER]: Done waiting for all views to stop loading +[10.596][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/url) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": { + + } +} + +[10.598][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with params { + "using": "xpath", + "value": ".//body" +} + +[10.598][FINER]: Waiting for all views to stop loading... +[10.614][FINER]: Done waiting for all views to stop loading +[10.625][FINER]: Waiting for all views to stop loading... +[10.626][FINER]: Done waiting for all views to stop loading +[10.626][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/elements) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": [ { + "ELEMENT": ":wdc:1359882799681" + } ] +} + +[10.879][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with params { + "args": [ ], + "script": "return JSON.stringify(window.performance.timing)" +} + +[10.879][FINER]: Waiting for all views to stop loading... +[10.879][FINER]: Done waiting for all views to stop loading +[10.884][FINER]: Waiting for all views to stop loading... +[10.884][FINER]: Done waiting for all views to stop loading +[10.884][FINE]: Command finished (/session/dd049c90f5fbd0d2f8f44d6c45386e1e/execute) with response { + "sessionId": "dd049c90f5fbd0d2f8f44d6c45386e1e", + "status": 0, + "value": "{\"loadEventEnd\":1359882799585,\"loadEventStart\":1359882799582,\"domComplete\":1359882799582,\"domCont..." +} + +[10.886][FINE]: Command received (/session/dd049c90f5fbd0d2f8f44d6c45386e1e) +[10.945][INFO]: Chrome shutdown diff --git a/lib/website_benchmarker.rb b/lib/website_benchmarker.rb new file mode 100644 index 0000000..88817fe --- /dev/null +++ b/lib/website_benchmarker.rb @@ -0,0 +1,8 @@ +require 'website_benchmarker/version' +require 'website_benchmarker/test' +require 'website_benchmarker/results' +require 'website_benchmarker/timing_hash' +require 'website_benchmarker/row_formatter' + +module WebsiteBenchmarker +end diff --git a/lib/website_benchmarker/results.rb b/lib/website_benchmarker/results.rb new file mode 100644 index 0000000..a760afb --- /dev/null +++ b/lib/website_benchmarker/results.rb @@ -0,0 +1,36 @@ +module WebsiteBenchmarker + class Results + def initialize + @results = {} + end + + def add(timing_hash) + timing_hash.each do |key, value| + @results[key] ||= [] + + @results[key] << value + end + end + + def to_s + heading_s + rows_s + end + + private + + def heading_s + "\n" \ + + ''.center(35) \ + + 'Fastest'.ljust(10) \ + + 'Median'.ljust(10) \ + + 'Slowest'.ljust(10) \ + + "\n" \ + + '-' * 65 \ + + "\n\n" + end + + def rows_s + @results.map { |result| RowFormatter.new(result) }.join("\n") + end + end +end diff --git a/lib/website_benchmarker/row_formatter.rb b/lib/website_benchmarker/row_formatter.rb new file mode 100644 index 0000000..b8e3302 --- /dev/null +++ b/lib/website_benchmarker/row_formatter.rb @@ -0,0 +1,35 @@ +class RowFormatter + def initialize(result) + @name = result.first + @values = result.last + end + + def to_s + name_s + fastest_s + median_s + slowest_s + end + + private + + def name_s + name = @name.to_s.dup + name.gsub!(/([a-z\d])([A-Z])/,'\1 \2') + name.gsub!(/\b('?[a-z])/) { $1.capitalize } + name.gsub!('Dom ', 'DOM ') + name = "#{name}:" + name.ljust(35) + end + + def fastest_s + "#{@values.min}ms".ljust(10) + end + + def slowest_s + "#{@values.max}ms".ljust(10) + end + + def median_s + median = @values[ @values.length / 2 ] + + "#{median}ms".ljust(10) + end +end diff --git a/lib/website_benchmarker/test.rb b/lib/website_benchmarker/test.rb new file mode 100644 index 0000000..62132c1 --- /dev/null +++ b/lib/website_benchmarker/test.rb @@ -0,0 +1,29 @@ +require 'capybara' + +module WebsiteBenchmarker + class Test + extend Capybara::DSL + + Capybara.register_driver(:selenium_chrome) { |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) } + Capybara.current_driver = :selenium_chrome + + def self.run(url, loops=8) + @results = Results.new + + loops.times do + Capybara.reset_sessions! + + visit url + page.has_css?('body') + sleep 0.25 + + timing_json = JSON.parse(page.evaluate_script('JSON.stringify(window.performance.timing)')) + timing = TimingHash.new(timing_json) + + @results.add(timing) + end + + puts @results + end + end +end diff --git a/lib/website_benchmarker/timing_hash.rb b/lib/website_benchmarker/timing_hash.rb new file mode 100644 index 0000000..78b6ce8 --- /dev/null +++ b/lib/website_benchmarker/timing_hash.rb @@ -0,0 +1,16 @@ +module WebsiteBenchmarker + class TimingHash < Hash + def initialize(json) + # Remove 0 values as they indicate events that didn't occur + json = json.delete_if { |key, value| value == 0 } + + # Grab the start time and offset the values against it. + # Also reverse the values here so that the start ones are first + start_time = json.min_by(&:last).last + + json.map { |key, value| [key, value - start_time] }.reverse.each do |key, value| + self[key] = value + end + end + end +end diff --git a/lib/website_benchmarker/version.rb b/lib/website_benchmarker/version.rb new file mode 100644 index 0000000..13fe287 --- /dev/null +++ b/lib/website_benchmarker/version.rb @@ -0,0 +1,3 @@ +module WebsiteBenchmarker + VERSION = '0.0.1' +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..c49a4c7 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,7 @@ +RSpec.configure do |config| + config.treat_symbols_as_metadata_keys_with_true_values = true + config.run_all_when_everything_filtered = true + config.filter_run :focus + + config.order = 'random' +end diff --git a/spec/timings_spec.rb b/spec/timings_spec.rb new file mode 100644 index 0000000..083780a --- /dev/null +++ b/spec/timings_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe WebsiteBenchmarker do + describe '#add' do + let(:timing) { Timing.new(data) } + let(:data) { JSON.parse('{"loadEventEnd":1359854901824,"loadEventStart":1359854901820,"domComplete":1359854901820,"domContentLoadedEventEnd":1359854893376,"domContentLoadedEventStart":1359854893376,"domInteractive":1359854893376,"domLoading":1359854890140,"responseEnd":1359854893372,"responseStart":1359854890128,"requestStart":1359854889943,"secureConnectionStart":0,"connectEnd":1359854889940,"connectStart":1359854889940,"domainLookupEnd":1359854889940,"domainLookupStart":1359854889940,"fetchStart":1359854889940,"redirectEnd":0,"redirectStart":0,"unloadEventEnd":0,"unloadEventStart":0,"navigationStart":1359854889322}') } + + it 'adds a new timing' do + + end + end +end + diff --git a/website_benchmarker.gemspec b/website_benchmarker.gemspec new file mode 100644 index 0000000..fa9f90a --- /dev/null +++ b/website_benchmarker.gemspec @@ -0,0 +1,19 @@ +# -*- encoding: utf-8 -*- +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'website_benchmarker/version' + +Gem::Specification.new do |gem| + gem.name = "website_benchmarker" + gem.version = WebsiteBenchmarker::VERSION + gem.authors = ["Mario Visic"] + gem.email = ["mario@mariovisic.com"] + gem.description = %q{TODO: Write a gem description} + gem.summary = %q{TODO: Write a gem summary} + gem.homepage = "" + + gem.files = `git ls-files`.split($/) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.require_paths = ["lib"] +end