-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
79 lines (72 loc) · 2.01 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<meta charset="utf-8">
<script>
function testAdd10k() {
for (let i = 0; i < 10000; i++) {
e = document.createElement('p'); e.textContent = `line ${i}`; document.body.appendChild(e);
}
}
function testHtml() {
for (let i = 0; i < 10000; i++) {
e = document.createElement('p'); e.textContent = `line ${i}`; document.body.appendChild(e);
}
}
function testUpdateAll() {
const arr = Array.from(document.getElementsByTagName('p'));
for (let i = 0; i < arr.length - 1; i++) {
arr[i].textContent = 'asd';
}
}
function testUpdate100() {
const arr = Array.from(document.getElementsByTagName('p'));
for (let i = 0; i < arr.length - 1; i++) {
if (i % 100 === 0) {
arr[i].textContent = '100';
}
}
}
function removeAll() {
const arr = Array.from(document.getElementsByTagName('p'));
for (let i = arr.length - 1; i >= 0; i--) {
document.body.removeChild(arr[i]);
}
}
function testUpdate100Reflow(timestamp) {
const timerEl = document.getElementById('timer');
for (let i = 0; i < 100; i++) {
// trigger reflow
timerEl.offsetTop;
window.scrollX;
const el = document.getElementsByTagName('p')[5000 + i];
if (el) {
el.textContent = i;
el.getBoundingClientRect();
}
}
}
function update100Reflow() {
window.requestAnimationFrame((timestamp) => {
timeIt(testUpdate100Reflow);
});
}
function timeIt(func) {
setTimeout(() => {
let startTime = performance.now();
func()
let endTime = performance.now();
const timerEl = document.getElementById('timer');
timerEl.textContent = `Call to ${func.name} took ${endTime - startTime} milliseconds`;
}, 1000);
}
</script>
</head>
<body>
<button onclick="timeIt(testAdd10k)">testAdd10k</button>
<button onclick="timeIt(testUpdateAll)">testUpdateAll</button>
<button onclick="timeIt(testUpdate100)">testUpdate100</button>
<button onclick="update100Reflow()">update100Reflow</button>
<button onclick="timeIt(removeAll)">removeAll</button>
<div id="timer"></div>
</body>
</html>