Skip to content

Instantly share code, notes, and snippets.

@indianburger
Created October 24, 2014 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save indianburger/a3d20935a18453057456 to your computer and use it in GitHub Desktop.
Save indianburger/a3d20935a18453057456 to your computer and use it in GitHub Desktop.
Render time using browser-perf
var browserPerf = require('browser-perf'),
statistics = require("simple-statistics"),
async = require("async"),
BaseMetrics = require('browser-perf/lib/metrics/BaseMetrics'),
url = process.argv[2],
options = {
selenium: 'http://localhost:9515',
browsers: ['chrome'],
actions: waitForRender,
metrics: [renderMetric()]
},
TIMES = 10,
startTime,
loadTimes = [];
function runMeasurement (n, next) {
console.log("repeating n:", n);
browserPerf(url, function(err, result) {
next(err, result)
}, options);
}
async.timesSeries(TIMES, runMeasurement, function(err, results) {
if (err) throw err;
console.log("Mean:", statistics.mean(loadTimes));
console.log("Std:", statistics.standard_deviation(loadTimes));
});
function waitForRender (browser) {
return browser
.waitForElementByCss("body.rendered-all", 5000);
}
function renderMetric () {
return {
start : function() {
startTime = +new Date();
},
teardown: function() {
var loadTime = +new Date() - startTime;
loadTimes.push(loadTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment