2015-02-11 14:40:29 -05:00
|
|
|
var benchpress = require('benchpress/index.js');
|
2015-01-09 21:00:04 -05:00
|
|
|
var webdriver = require('protractor/node_modules/selenium-webdriver');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
runClickBenchmark: runClickBenchmark,
|
2015-01-27 12:53:22 -05:00
|
|
|
runBenchmark: runBenchmark,
|
2015-01-09 21:00:04 -05:00
|
|
|
verifyNoBrowserErrors: benchpress.verifyNoBrowserErrors
|
|
|
|
};
|
|
|
|
|
|
|
|
function runClickBenchmark(config) {
|
2015-01-27 12:53:22 -05:00
|
|
|
var buttons = config.buttons.map(function(selector) {
|
|
|
|
return $(selector);
|
|
|
|
});
|
|
|
|
config.work = function() {
|
|
|
|
buttons.forEach(function(button) {
|
|
|
|
button.click();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
runBenchmark(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
function runBenchmark(config) {
|
2015-01-15 18:14:54 -05:00
|
|
|
var globalParams = browser.params;
|
|
|
|
getScaleFactor(globalParams.benchmark.scaling).then(function(scaleFactor) {
|
|
|
|
var params = config.params.map(function(param) {
|
|
|
|
return {
|
|
|
|
name: param.name, value: applyScaleFactor(param.value, scaleFactor, param.scale)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var benchmarkConfig = Object.create(globalParams.benchmark);
|
|
|
|
benchmarkConfig.id = globalParams.lang+'.'+config.id;
|
|
|
|
benchmarkConfig.params = params;
|
|
|
|
benchmarkConfig.scaleFactor = scaleFactor;
|
|
|
|
|
|
|
|
var url = encodeURI(config.url + '?' + params.map(function(param) {
|
|
|
|
return param.name + '=' + param.value;
|
|
|
|
}).join('&'));
|
|
|
|
browser.get(url);
|
2015-01-27 12:53:22 -05:00
|
|
|
benchpress.runBenchmark(benchmarkConfig, config.work);
|
2015-01-09 21:00:04 -05:00
|
|
|
});
|
2015-01-15 18:14:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getScaleFactor(possibleScalings) {
|
|
|
|
return browser.executeScript('return navigator.userAgent').then(function(userAgent) {
|
|
|
|
var scaleFactor = 1;
|
|
|
|
possibleScalings.forEach(function(entry) {
|
|
|
|
if (userAgent.match(entry.userAgent)) {
|
|
|
|
scaleFactor = entry.value;
|
|
|
|
}
|
2015-01-09 21:00:04 -05:00
|
|
|
});
|
2015-01-15 18:14:54 -05:00
|
|
|
return scaleFactor;
|
2015-01-09 21:00:04 -05:00
|
|
|
});
|
2015-01-15 18:14:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function applyScaleFactor(value, scaleFactor, method) {
|
|
|
|
if (method === 'log2') {
|
|
|
|
return value + Math.log2(scaleFactor);
|
|
|
|
} else if (method === 'sqrt') {
|
|
|
|
return value * Math.sqrt(scaleFactor);
|
|
|
|
} else if (method === 'linear') {
|
|
|
|
return value * scaleFactor;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
2015-01-09 21:00:04 -05:00
|
|
|
}
|