forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone-with-focus.html
More file actions
61 lines (50 loc) · 1.93 KB
/
clone-with-focus.html
File metadata and controls
61 lines (50 loc) · 1.93 KB
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
<!DOCTYPE html>
<html>
<body>
<input id="input">
<ul id="list"><li><span></span></li></ul>
<div id="console"></div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var listElement = document.getElementById('list');
var templateElement = list.firstChild;
var inputElement = document.getElementById('input');
function test(numberOfElements, focusInput)
{
if (focusInput)
inputElement.focus();
var startTime = performance.now();
for (var i = 0; i < numberOfElements; i++) {
var clone = templateElement.cloneNode(true);
clone.childNodes[0].textContent = i;
listElement.appendChild(clone);
}
var endTime = performance.now();
if (focusInput)
inputElement.blur();
const originalItem = listElement.firstChild;
listElement.textContent = '';
listElement.appendChild(originalItem);
return endTime - startTime;
}
function log(str)
{
var element = document.createElement('div');
element.appendChild(document.createTextNode(str));
document.getElementById('console').appendChild(element);
}
const start = performance.now();
let factor = 0;
while (test(1000 * factor, false) < 5)
factor++;
var timeWithoutFocus = test(1000 * factor, false);
var timeWithFocus = test(1000 * factor, true);
if (Math.abs(timeWithFocus - timeWithoutFocus) <= timeWithoutFocus) {
log('PASS. Cloning elements takes roughly as long with as without focus.');
} else {
log('FAIL. Cloning 1000 elements with focus took ' + timeWithFocus + 'ms, without took ' + timeWithoutFocus + 'ms.');
}
</script>
</body>
</html>