[benchmark] Do not call measureValue in warm-up iterations
[email protected]
Review URL: https://codereview.appspot.com/154680043
git-svn-id: https://pywebsocket.googlecode.com/svn/trunk/src@854 4ff78f4a-9131-11de-b045-6380ec9940d4
diff --git a/example/benchmark.js b/example/benchmark.js
index d347ae9..5645656 100644
--- a/example/benchmark.js
+++ b/example/benchmark.js
@@ -32,7 +32,7 @@
sockets = [];
}
-function sendBenchmarkStep(size, config) {
+function sendBenchmarkStep(size, config, isWarmUp) {
timerID = null;
var totalSize = 0;
@@ -50,7 +50,8 @@
return;
}
- calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
+ calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
+ isWarmUp);
runNextTask(config);
};
@@ -89,7 +90,7 @@
}
}
-function receiveBenchmarkStep(size, config) {
+function receiveBenchmarkStep(size, config, isWarmUp) {
timerID = null;
var totalSize = 0;
@@ -116,7 +117,8 @@
return;
}
- calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
+ calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
+ isWarmUp);
runNextTask(config);
};
@@ -212,10 +214,6 @@
function addTasks(config, stepFunc) {
for (var i = 0;
i < config.numWarmUpIterations + config.numIterations; ++i) {
- // Ignore the first |config.numWarmUpIterations| iterations.
- if (i == config.numWarmUpIterations)
- addResultClearingTask(config);
-
var multiplierIndex = 0;
for (var size = config.startSize;
size <= config.stopThreshold;
@@ -223,7 +221,8 @@
var task = stepFunc.bind(
null,
size,
- config);
+ config,
+ i < config.numWarmUpIterations);
tasks.push(task);
size *= config.multipliers[
multiplierIndex % config.multipliers.length];
@@ -241,14 +240,6 @@
});
}
-function addResultClearingTask(config) {
- tasks.push(function(){
- timerID = null;
- clearAverageData();
- runNextTask(config);
- });
-}
-
function sendBenchmark(config) {
config.addToLog('Send benchmark');
config.addToLog(buildLegendString(config));
diff --git a/example/util.js b/example/util.js
index a1cad49..de60509 100644
--- a/example/util.js
+++ b/example/util.js
@@ -76,17 +76,20 @@
return Math.round(size / timeSpentInMs * 1000) / 1000;
}
-function calculateAndLogResult(config, size, startTimeInMs, totalSize) {
+function calculateAndLogResult(config, size, startTimeInMs, totalSize,
+ isWarmUp) {
var timeSpentInMs = getTimeStamp() - startTimeInMs;
var speed = calculateSpeedInKB(totalSize, timeSpentInMs);
var timePerMessageInMs = timeSpentInMs / (totalSize / size);
- if (!results[size]) {
- results[size] = {n: 0, sum_t: 0, sum_t2: 0};
+ if (!isWarmUp) {
+ config.measureValue(timePerMessageInMs);
+ if (!results[size]) {
+ results[size] = {n: 0, sum_t: 0, sum_t2: 0};
+ }
+ results[size].n ++;
+ results[size].sum_t += timePerMessageInMs;
+ results[size].sum_t2 += timePerMessageInMs * timePerMessageInMs;
}
- config.measureValue(timePerMessageInMs);
- results[size].n ++;
- results[size].sum_t += timePerMessageInMs;
- results[size].sum_t2 += timePerMessageInMs * timePerMessageInMs;
config.addToLog(formatResultInKiB(size, timePerMessageInMs, -1, speed,
config.printSize));
}
diff --git a/example/xhr_benchmark.js b/example/xhr_benchmark.js
index 233c7cb..15a1347 100644
--- a/example/xhr_benchmark.js
+++ b/example/xhr_benchmark.js
@@ -53,7 +53,7 @@
return data;
}
-function sendBenchmarkStep(size, config) {
+function sendBenchmarkStep(size, config, isWarmUp) {
timerID = null;
benchmark.startTimeInMs = null;
@@ -89,7 +89,8 @@
return;
}
- calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
+ calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
+ isWarmUp);
destroyAllXHRs();
@@ -134,7 +135,7 @@
}
}
-function receiveBenchmarkStep(size, config) {
+function receiveBenchmarkStep(size, config, isWarmUp) {
timerID = null;
benchmark.startTimeInMs = null;
@@ -160,7 +161,8 @@
return;
}
- calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize);
+ calculateAndLogResult(config, size, benchmark.startTimeInMs, totalSize,
+ isWarmUp);
destroyAllXHRs();
@@ -271,10 +273,6 @@
function addTasks(config, stepFunc) {
for (var i = 0;
i < config.numWarmUpIterations + config.numIterations; ++i) {
- // Ignore the first |config.numWarmUpIterations| iterations.
- if (i == config.numWarmUpIterations)
- addResultClearingTask(config);
-
var multiplierIndex = 0;
for (var size = config.startSize;
size <= config.stopThreshold;
@@ -282,7 +280,8 @@
var task = stepFunc.bind(
null,
size,
- config);
+ config,
+ i < config.numWarmUpIterations);
tasks.push(task);
size *= config.multipliers[
multiplierIndex % config.multipliers.length];
@@ -300,14 +299,6 @@
});
}
-function addResultClearingTask(config) {
- tasks.push(function(){
- timerID = null;
- clearAverageData();
- runNextTask(config);
- });
-}
-
// --------------------------------
function sendBenchmark(config) {