Permalink
Browse files

Logging removed; stats display implemented

  • Loading branch information...
1 parent 1eac2a9 commit 9e22fdb8a8796b8b1a832cbd4a9ed1661a6ad961 @penartur committed May 4, 2012
Showing with 53 additions and 19 deletions.
  1. +50 −18 lib/benchmark.js
  2. +3 −1 package.json
View
68 lib/benchmark.js
@@ -21,7 +21,7 @@ var getTimer = function (timerType) {
var statistics = {
temporalDisrepancy: function (list) {
- var sliceLength = Math.min(list.length / 2, 24);
+ var sliceLength = Math.min(list.length / 2, 48);
return Math.round(100 * this.trimmedMean(list.slice(list.length - sliceLength, list.length)) / this.trimmedMean(list.slice(0, sliceLength))) / 100;
},
sort: function (list) {
@@ -67,10 +67,10 @@ var statistics = {
var median = this.median(list);
var trimmedMean = this.mean(list.slice(list.length / 3 - 1, 2 * list.length / 3 - 1));
var result = {
- trMean: trimmedMean
- //, median: median,
- , teDisrepancy: temporalDisrepancy
- //, mean: mean
+ trimmedMean: trimmedMean
+ , median: median
+ , temporalDisrepancy: temporalDisrepancy
+ , mean: mean
, max: max
, num: num
};
@@ -116,15 +116,14 @@ var BenchmarkContext = function (benchmark, simultaneousRequests, done) {
}
BenchmarkContext.prototype.onDone = function () {
+ var stats = {};
for (var pageName in this.benchmark.pages) {
- var averages = {};
+ stats[pageName] = {};
for (var engineName in this.benchmark.engines) {
- averages[engineName] = statistics.all(this.responseTimes[pageName][engineName]);
+ stats[pageName][engineName] = statistics.all(this.responseTimes[pageName][engineName]);
}
- console.log("For page " + pageName);
- console.log(averages);
}
- this.done();
+ this.done(this.simultaneousRequests, stats);
}
BenchmarkContext.prototype.requestPage = function (url, expectedLength, callback) {
@@ -171,11 +170,9 @@ BenchmarkContext.prototype.runEngine = function (engineName, over) {
queue.go();
}
-BenchmarkContext.prototype.run = function (done) {
- console.log("");
- console.log("Measuring average reponse time for " + this.simultaneousRequests + " simultaneous requests");
+BenchmarkContext.prototype.run = function () {
- http.globalAgent.maxSockets = this.simultaneousRequests;
+ http.globalAgent.maxSockets = this.simultaneousRequests; //TODO: replace this global state changing with something else
var metaQueue = new WorkingQueue(1);
metaQueue.hold();
@@ -186,12 +183,14 @@ BenchmarkContext.prototype.run = function (done) {
metaQueue.go();
};
-Benchmark.prototype.run = function (simultaneousRequests, done) {
- var context = new BenchmarkContext(this, simultaneousRequests, done);
- context.run(done);
+//callback is function(simultaneousRequests, stats)
+Benchmark.prototype.run = function (simultaneousRequests, callback) {
+ var context = new BenchmarkContext(this, simultaneousRequests, callback);
+ context.run(callback);
}
-Benchmark.prototype.runMultiple = function (simultaneousRequestsList, done) {
+//callback is function(simultaneousRequests, stats)
+Benchmark.prototype.runMultiple = function (simultaneousRequestsList, callback) {
var queue = new WorkingQueue(1);
queue.hold();
for (var i in simultaneousRequestsList) {
@@ -201,4 +200,37 @@ Benchmark.prototype.runMultiple = function (simultaneousRequestsList, done) {
queue.go();
}
+Benchmark.prototype.showStats = function (simultaneousRequests, stats) {
+ var Table = require('cli-table');
+ console.log("Statistics for " + simultaneousRequests + " simultaneous requests");
+ for (var pageName in stats) {
+ console.log(pageName);
+ var table = new Table({
+ head: [
+ 'Engine',
+ 'Trimmed mean',
+ 'Median',
+ 'Temporal disrepancy',
+ 'Mean',
+ 'Max',
+ 'Sample size'
+ ]
+ });
+ for (var engineName in stats[pageName]) {
+ var entry = stats[pageName][engineName];
+ table.push([
+ engineName,
+ entry.trimmedMean,
+ entry.median,
+ entry.temporalDisrepancy,
+ entry.mean,
+ entry.max,
+ entry.num
+ ]);
+ }
+ console.log(table.toString());
+ console.log();
+ }
+}
+
module.exports = Benchmark;
View
4 package.json
@@ -13,7 +13,9 @@
, "capisce": ">= 0.4.3"
},
"devDependencies": {},
- "optionalDependencies": {},
+ "optionalDependencies": {
+ "cli-table": ">= 0.0.1"
+ },
"engines": {
"node": ">= 0.6.15"
}

0 comments on commit 9e22fdb

Please sign in to comment.