From 97c50e8761d579c76c746fc2a8a24379f9971791 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sat, 4 May 2019 12:37:19 +0200 Subject: [PATCH] Added performance test for DOMRect For #253 --- test/domRectTest.html | 3 ++- test/domRectTest.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/test/domRectTest.html b/test/domRectTest.html index b8e18e2..88ceb91 100644 --- a/test/domRectTest.html +++ b/test/domRectTest.html @@ -50,7 +50,8 @@

Hash:
Data:
- + + diff --git a/test/domRectTest.js b/test/domRectTest.js index 4ce13c1..921396d 100644 --- a/test/domRectTest.js +++ b/test/domRectTest.js @@ -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();