Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Automatic expected page length detection implemented

  • Loading branch information...
commit 74d1620e81b13cb2164264084f43636823896295 1 parent c07a8ae
@penartur authored
Showing with 37 additions and 9 deletions.
  1. +37 −9 lib/benchmark.js
View
46 lib/benchmark.js
@@ -35,10 +35,36 @@ 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) {
+ if (error) {
+ throw new Error("An error occured while trying to process " + url + ": " + error);
+ } else {
+ this.pagesExpectedLength[pageName][engineName] = body.length;
+ over();
+ }
+ }).bind(this));
+}
- this.pagesExpectedLength = {};
- for (var pageName in pages) {
- this.pagesExpectedLength[pageName] = {};
+Benchmark.prototype.init = function (done) {
+ if (this.pagesExpectedLength) {
+ process.nextTick(done);
+ } else {
+ this.pagesExpectedLength = {};
+ for (var pageName in this.pages) {
+ this.pagesExpectedLength[pageName] = {};
+ }
+ var queue = new WorkingQueue(1);
+ queue.whenDone(done);
+ for (var pageName in this.pages) {
+ for (var engineName in this.engines) {
+ queue.perform(this.fillExpectedLength.bind(this), pageName, engineName);
+ }
+ }
+ queue.go();
}
}
@@ -96,7 +122,7 @@ BenchmarkContext.prototype.requestPage = function (url, expectedLength, callback
BenchmarkContext.prototype.runPage = function (engineName, pageName, over) {
this.requestPage(
this.benchmark.engines[engineName] + this.benchmark.pages[pageName].url,
- this.benchmark.pages[pageName].expectedLength[engineName],
+ this.benchmark.pagesExpectedLength[pageName][engineName],
(function (err, total) {
if (err) {
console.log(err);
@@ -150,11 +176,13 @@ BenchmarkContext.prototype.run = function () {
};
Benchmark.prototype.doRun = function (simultaneousRequests, callback, over) {
- var context = new BenchmarkContext(this, simultaneousRequests, callback);
- context.run(function (simultaneousRequests, stats) {
- callback(simultaneousRequests, stats);
- over();
- });
+ this.init((function () {
+ var context = new BenchmarkContext(this, simultaneousRequests, callback);
+ context.run(function (simultaneousRequests, stats) {
+ callback(simultaneousRequests, stats);
+ over();
+ })
+ }).bind(this));
}
//callback is function(simultaneousRequests, stats)
Please sign in to comment.
Something went wrong with that request. Please try again.