mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +01:00
Made performance test manual an cumulative.
This commit is contained in:
parent
4dc3418769
commit
95bb415f86
@ -8,14 +8,23 @@ var createLog = function(){
|
|||||||
var logDiv = document.createElement("div");
|
var logDiv = document.createElement("div");
|
||||||
logDiv.className = "log";
|
logDiv.className = "log";
|
||||||
div.appendChild(logDiv);
|
div.appendChild(logDiv);
|
||||||
return function createLine(str){
|
return {
|
||||||
var logLine = document.createElement("div");
|
createButton: function createButton(text, callback){
|
||||||
logLine.className = "logLine";
|
var button = document.createElement("button");
|
||||||
logDiv.appendChild(logLine);
|
button.className = "logButton";
|
||||||
logLine.textContent = str;
|
logDiv.appendChild(button);
|
||||||
return function updateLine(str){
|
button.textContent = text;
|
||||||
|
button.addEventListener("click", callback);
|
||||||
|
},
|
||||||
|
createLine: function createLine(str, type = "div"){
|
||||||
|
var logLine = document.createElement(type);
|
||||||
|
logLine.className = "logLine";
|
||||||
|
logDiv.appendChild(logLine);
|
||||||
logLine.textContent = str;
|
logLine.textContent = str;
|
||||||
};
|
return function updateLine(str){
|
||||||
|
logLine.textContent = str;
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
@ -25,46 +34,53 @@ var performTest = function(){
|
|||||||
|
|
||||||
return function performTest(name, func, innerRunLength, outerRunLength){
|
return function performTest(name, func, innerRunLength, outerRunLength){
|
||||||
var log = createLog();
|
var log = createLog();
|
||||||
log("test " + name);
|
log.createLine("test " + name, "h3");
|
||||||
var line = log("starting");
|
var line = log.createLine("");
|
||||||
var time = 0;
|
var time = 0;
|
||||||
var time2 = 0;
|
var time2 = 0;
|
||||||
var min = Number.POSITIVE_INFINITY;
|
var min = Number.POSITIVE_INFINITY;
|
||||||
var max = 0;
|
var max = 0;
|
||||||
var outerI = 0;
|
var outerI = 0;
|
||||||
|
var outerRunIncrease = outerRunLength;
|
||||||
if (func.prepareOnce){
|
if (func.prepareOnce){
|
||||||
func.prepareOnce();
|
func.prepareOnce();
|
||||||
}
|
}
|
||||||
function run(){
|
log.createButton("measure", function(){
|
||||||
for (var i = 0; i < innerRunLength; i += 1){
|
line("starting");
|
||||||
if (func.prepare){
|
line2("");
|
||||||
func.prepare();
|
function run(){
|
||||||
|
for (var i = 0; i < innerRunLength; i += 1){
|
||||||
|
if (func.prepare){
|
||||||
|
func.prepare();
|
||||||
|
}
|
||||||
|
var start = performance.now();
|
||||||
|
func.test();
|
||||||
|
var end = performance.now();
|
||||||
|
var duration = end - start;
|
||||||
|
min = Math.min(min, duration);
|
||||||
|
max = Math.max(max, duration);
|
||||||
|
time2 += duration * duration;
|
||||||
|
time += duration;
|
||||||
|
}
|
||||||
|
outerI += 1;
|
||||||
|
var totalRunI = outerI * innerRunLength;
|
||||||
|
line(
|
||||||
|
"finished run " + totalRunI + " from " + (innerRunLength * outerRunLength) +
|
||||||
|
" -> average: " + (time / totalRunI).toFixed(2) +
|
||||||
|
"(\u00B1" + Math.sqrt((time2 - time * time / totalRunI) / totalRunI).toFixed(2) + ") ms " +
|
||||||
|
"(min: " + min.toFixed(2) + "ms, max: " + max.toFixed(2) + "ms)"
|
||||||
|
);
|
||||||
|
if (outerI < outerRunLength){
|
||||||
|
window.setTimeout(run, 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outerRunLength += outerRunIncrease;
|
||||||
|
line2("finished");
|
||||||
}
|
}
|
||||||
var start = performance.now();
|
|
||||||
func.test();
|
|
||||||
var end = performance.now();
|
|
||||||
var duration = end - start;
|
|
||||||
min = Math.min(min, duration);
|
|
||||||
max = Math.max(max, duration);
|
|
||||||
time2 += duration * duration;
|
|
||||||
time += duration;
|
|
||||||
}
|
}
|
||||||
outerI += 1;
|
window.setTimeout(run, 10);
|
||||||
var totalRunI = outerI * innerRunLength;
|
});
|
||||||
line(
|
var line2 = log.createLine("");
|
||||||
"finished run " + totalRunI + " from " + (innerRunLength * outerRunLength) +
|
|
||||||
" -> average: " + (time / totalRunI).toFixed(2) +
|
|
||||||
"(\u00B1" + Math.sqrt((time2 - time * time / totalRunI) / totalRunI).toFixed(2) + ") ms " +
|
|
||||||
"(min: " + min.toFixed(2) + "ms, max: " + max.toFixed(2) + "ms)"
|
|
||||||
);
|
|
||||||
if (outerI < outerRunLength){
|
|
||||||
window.setTimeout(run, 10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log("finished");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.setTimeout(run, 10);
|
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user