Revision control

1
<!DOCTYPE html>
2
<html>
3
<body>
4
<input id="input">
5
<ul id="list"><li><span></span></li></ul>
6
<div id="console"></div>
7
8
<script>
9
if (window.testRunner)
10
testRunner.dumpAsText();
11
12
var listElement = document.getElementById('list');
13
var templateElement = list.firstChild;
14
var inputElement = document.getElementById('input');
15
16
function test(numberOfElements, focusInput)
17
{
18
if (focusInput)
19
inputElement.focus();
20
21
var startTime = performance.now();
22
for (var i = 0; i < numberOfElements; i++) {
23
var clone = templateElement.cloneNode(true);
24
clone.childNodes[0].textContent = i;
25
listElement.appendChild(clone);
26
}
27
var endTime = performance.now();
28
29
if (focusInput)
30
inputElement.blur();
31
32
const originalItem = listElement.firstChild;
33
listElement.textContent = '';
34
listElement.appendChild(originalItem);
35
36
return endTime - startTime;
37
}
38
39
function log(str)
40
{
41
var element = document.createElement('div');
42
element.appendChild(document.createTextNode(str));
43
document.getElementById('console').appendChild(element);
44
}
45
46
const start = performance.now();
47
let factor = 0;
48
while (test(1000 * factor, false) < 5)
49
factor++;
50
51
var timeWithoutFocus = test(1000 * factor, false);
52
var timeWithFocus = test(1000 * factor, true);
53
54
if (Math.abs(timeWithFocus - timeWithoutFocus) <= timeWithoutFocus) {
55
log('PASS. Cloning elements takes roughly as long with as without focus.');
56
} else {
57
log('FAIL. Cloning 1000 elements with focus took ' + timeWithFocus + 'ms, without took ' + timeWithoutFocus + 'ms.');
58
}
59
</script>
60
</body>
61
</html>