Added performance test for DOMRect

For #253
This commit is contained in:
kkapsner 2019-05-04 12:37:19 +02:00
parent 9891c1d9b8
commit 97c50e8761
2 changed files with 34 additions and 2 deletions

View File

@ -50,7 +50,8 @@
<h2 class="title"></h2>
Hash: <span class="hash"></span><br>
Data: <span class="data"></span><br>
<button>refresh</button>
<button class="refresh">refresh</button>
<button class="performance">measure performance</button>
</div>
</div>
<script src="domRectTest.js"></script>

View File

@ -80,7 +80,38 @@
}
const output = template.cloneNode(true);
output.querySelector(".title").textContent = title;
output.querySelector("button").addEventListener("click", performTest);
output.querySelector(".refresh").addEventListener("click", performTest);
output.querySelector(".performance").addEventListener("click", function(){
let count = 200;
return function(){
let duration = 0;
let i = 0;
while (duration < 1000){
const start = Date.now();
for (; i < count; i += 1){
const rects = getElements().map(function(element){
return {
name: element.dataset.name,
data: callback(element)
};
});
const data = new Float64Array(rects.length * properties.length);
rects.forEach(function(rect, i){
properties.forEach(function(property, j){
data[i * properties.length + j] = rect.data[property];
});
});
}
duration += Date.now() - start;
if (duration < 1000){
count += Math.ceil(
count * (1000 - duration) / 1000
);
}
}
alert((count / (duration / 1000)).toFixed(2) + " tests/s (" + count + " samples)");
};
}());
container.appendChild(output);
performTest();