Permalink
Browse files

Autolint compliance

  • Loading branch information...
penartur committed May 5, 2012
1 parent 386d0bf commit a38bb00cbd13fe10f71b4a3b2a86ddba2e21161c
Showing with 139 additions and 88 deletions.
  1. +12 −0 autolint.js
  2. +44 −29 lib/benchmark-context.js
  3. +27 −23 lib/benchmark.js
  4. +17 −9 lib/statistics-display.js
  5. +36 −26 lib/statistics.js
  6. +3 −1 lib/timers/datetimer.js
View
@@ -0,0 +1,12 @@
+module.exports = {
+ paths: [ "./**/*.js" ],
+ linter: "jslint",
+ linterOptions: {
+ maxlen: 120,
+ node: true,
+ devel: true,
+ forin: true,
+ plusplus: true
+ },
+ excludes: ["node_modules"]
+};
View
@@ -1,4 +1,4 @@
-"use strict";
+"use strict";
var request = require('request');
var WorkingQueue = require('capisce').WorkingQueue;
@@ -9,38 +9,46 @@ var statistics = require('./statistics');
//Instances of BenchmarkContext are one-time only
var BenchmarkContext = function (benchmark, simultaneousRequests, done) {
+ var pageName,
+ engineName;
+
this.benchmark = benchmark;
this.simultaneousRequests = simultaneousRequests;
this.done = done;
- if (!(simultaneousRequests >= 1)) {
+ if (typeof simultaneousRequests !== "number") {
+ throw new Error("simultaneousRequests must be an integer; " + (typeof simultaneousRequests) + " passed");
+ }
+ if (simultaneousRequests < 1) {
throw new Error("simultaneousRequests must be at least 1; " + simultaneousRequests + " passed");
}
this.responseTimes = {};
- for (var pageName in this.benchmark.pages) {
+ for (pageName in this.benchmark.pages) {
this.responseTimes[pageName] = {};
- for (var engineName in this.benchmark.engines) {
+ for (engineName in this.benchmark.engines) {
this.responseTimes[pageName][engineName] = [];
}
}
this.totals = {};
-}
+};
BenchmarkContext.prototype.onDone = function () {
- var perPage = {};
- for (var pageName in this.benchmark.pages) {
+ var pageName,
+ engineName,
+ perPage = {};
+ for (pageName in this.benchmark.pages) {
perPage[pageName] = {};
- for (var engineName in this.benchmark.engines) {
+ for (engineName in this.benchmark.engines) {
perPage[pageName][engineName] = statistics.all(this.responseTimes[pageName][engineName]);
}
}
this.done(this.simultaneousRequests, {
perPage: perPage,
totals: this.totals
});
-}
+};
BenchmarkContext.prototype.requestPage = function (url, expectedLength, callback) {
var timer = this.benchmark.timers.start();
@@ -49,7 +57,7 @@ BenchmarkContext.prototype.requestPage = function (url, expectedLength, callback
if (error) {
callback(new Error("An error occured while trying to process " + url + ": " + error), elapsed);
} else {
- if (body.length != expectedLength) {
+ if (body.length !== expectedLength) {
callback(new Error("Expected " + expectedLength + " bytes, got " + body.length + " bytes"), elapsed);
} else {
callback(false, elapsed);
@@ -62,52 +70,59 @@ BenchmarkContext.prototype.runPage = function (engineName, pageName, over) {
this.requestPage(
this.benchmark.engines[engineName] + this.benchmark.pages[pageName].url,
this.benchmark.pagesExpectedLength[pageName][engineName],
- (function (err, total) {
+ function (err, total) {
if (err) {
console.log(err);
} else {
this.responseTimes[pageName][engineName].push(total);
}
over();
- }).bind(this)
+ }.bind(this)
);
-}
+};
BenchmarkContext.prototype.runEngine = function (engineName, over) {
- var tasks = 0;
- //console.log("runEngine");
- var queue = new WorkingQueue(this.simultaneousRequests);
+ var i,
+ pageName,
+ j,
+ timer,
+ tasks = 0,
+ queue = new WorkingQueue(this.simultaneousRequests);
queue.hold();
- for (var i = 0; i < this.benchmark.options.iterations * this.simultaneousRequests; i++) {
- for (var pageName in this.benchmark.pages) {
- for (var j = 0; j < this.benchmark.pages[pageName].weight; j++) {
+ for (i = 0; i < this.benchmark.options.iterations * this.simultaneousRequests; i++) {
+ for (pageName in this.benchmark.pages) {
+ for (j = 0; j < this.benchmark.pages[pageName].weight; j++) {
queue.perform(this.runPage.bind(this), engineName, pageName);
tasks++;
}
}
}
- var timer = this.benchmark.timers.start();
- queue.whenDone((function () {
+ timer = this.benchmark.timers.start();
+ queue.whenDone(function () {
+ var timeout;
this.totals[engineName] = {
time: timer.elapsed(),
tasks: tasks
};
- var timeout = 0;
- if (os.platform() == 'win32') {
+
+ timeout = 0;
+ if (os.platform() === 'win32') {
timeout = this.simultaneousRequests * 2000; //to workaround ENOBUFS
}
- //console.log("done, waiting " + timeout + "ms");
setTimeout(over, timeout);
- }).bind(this));
+ }.bind(this));
queue.go();
-}
+};
BenchmarkContext.prototype.run = function () {
+ var metaQueue,
+ engineName;
- http.globalAgent.maxSockets = this.simultaneousRequests; //TODO: replace this global state changing with something else
- var metaQueue = new WorkingQueue(1);
+ //TODO: replace this global state changing with something else
+ http.globalAgent.maxSockets = this.simultaneousRequests;
+ metaQueue = new WorkingQueue(1);
metaQueue.hold();
- for (var engineName in this.benchmark.engines) {
+ for (engineName in this.benchmark.engines) {
metaQueue.perform(this.runEngine.bind(this), engineName);
}
metaQueue.whenDone(this.onDone.bind(this));
View
@@ -9,16 +9,16 @@ var statisticsDisplay = require('./statistics-display');
var TIMERTYPES = {
DATETIMER: 'datetimer'
-}
+};
var getTimer = function (timerType) {
switch (timerType) {
- case TIMERTYPES.DATETIMER:
- return dateTimer;
- default:
- throw new Error("Unknown timer type " + timerType);
+ case TIMERTYPES.DATETIMER:
+ return dateTimer;
+ default:
+ throw new Error("Unknown timer type " + timerType);
}
-}
+};
var Benchmark = function (engines, pages, options) {
this.engines = engines;
@@ -34,64 +34,68 @@ var Benchmark = function (engines, pages, options) {
this.options.timerType = options.timerType;
}
this.timers = getTimer(this.options.timerType);
-}
+};
Benchmark.prototype.fillExpectedLength = function (pageName, engineName, over) {
var url = this.engines[engineName] + this.pages[pageName].url;
- request(url, (function (error, response, body) {
+ request(url, function (error, response, body) {
if (error) {
throw new Error("An error occured while trying to process " + url + ": " + error);
} else {
this.pagesExpectedLength[pageName][engineName] = body.length;
over();
}
- }).bind(this));
-}
+ }.bind(this));
+};
Benchmark.prototype.init = function (done) {
+ var pageName,
+ queue,
+ engineName;
if (this.pagesExpectedLength) {
process.nextTick(done);
} else {
this.pagesExpectedLength = {};
- for (var pageName in this.pages) {
+ for (pageName in this.pages) {
this.pagesExpectedLength[pageName] = {};
}
- var queue = new WorkingQueue(1);
+ queue = new WorkingQueue(1);
queue.whenDone(done);
- for (var pageName in this.pages) {
- for (var engineName in this.engines) {
+ for (pageName in this.pages) {
+ for (engineName in this.engines) {
queue.perform(this.fillExpectedLength.bind(this), pageName, engineName);
}
}
queue.go();
}
-}
+};
Benchmark.prototype.doRun = function (simultaneousRequests, callback, over) {
- this.init((function () {
+ this.init(function () {
var context = new BenchmarkContext(this, simultaneousRequests, function (simultaneousRequests, stats) {
callback(simultaneousRequests, stats);
over();
});
- context.run()
- }).bind(this));
-}
+ context.run();
+ }.bind(this));
+};
//callback is function(simultaneousRequests, stats)
Benchmark.prototype.run = function (simultaneousRequests, callback) {
this.doRun(simultaneousRequests, callback, function () { });
-}
+};
//callback is function(simultaneousRequests, stats)
Benchmark.prototype.runMultiple = function (simultaneousRequestsList, callback, done) {
- var queue = new WorkingQueue(1);
+ var i,
+ queue = new WorkingQueue(1);
queue.hold();
- for (var i in simultaneousRequestsList) {
+ for (i = 0; i < simultaneousRequestsList.length; i++) {
queue.perform(this.doRun.bind(this), simultaneousRequestsList[i], callback);
}
queue.whenDone(done);
queue.go();
-}
+};
Benchmark.statisticsDisplay = statisticsDisplay;
View
@@ -1,14 +1,22 @@
-"use strict";
+"use strict";
exports.showCliTable = function (simultaneousRequests, stats) {
- var Table = require('cli-table');
+ var table,
+ engineName,
+ pageName,
+ entry,
+ Table = require('cli-table');
+
console.log("Statistics for " + simultaneousRequests + " simultaneous requests");
- for (var engineName in stats.totals) {
- console.log("Processing " + engineName + " took " + stats.totals[engineName].time + " (" + (stats.totals[engineName].time / stats.totals[engineName].tasks) + " per request)");
+ for (engineName in stats.totals) {
+ console.log(
+ "Processing " + engineName + " took " + stats.totals[engineName].time +
+ " (" + (stats.totals[engineName].time / stats.totals[engineName].tasks) + " per request)"
+ );
}
- for (var pageName in stats.perPage) {
+ for (pageName in stats.perPage) {
console.log(pageName);
- var table = new Table({
+ table = new Table({
head: [
'Engine',
'Trimmed mean',
@@ -43,8 +51,8 @@ exports.showCliTable = function (simultaneousRequests, stats) {
'right'
]
});
- for (var engineName in stats.perPage[pageName]) {
- var entry = stats.perPage[pageName][engineName];
+ for (engineName in stats.perPage[pageName]) {
+ entry = stats.perPage[pageName][engineName];
table.push([
engineName,
entry.trimmedMean,
@@ -60,4 +68,4 @@ exports.showCliTable = function (simultaneousRequests, stats) {
console.log(table.toString());
console.log();
}
-}
+};
Oops, something went wrong.

0 comments on commit a38bb00

Please sign in to comment.