-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmany_flat.html
50 lines (43 loc) · 1.44 KB
/
many_flat.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
<!DOCTYPE html>
<html>
<head></head>
<body>
<!--
Benchmarks an HTML document with many small consecutive
<template shadowroot> elements.
-->
<script type="module">
import { hydrateShadowRoots as manualWalkHydration } from '../_implementation/manual_walk.js';
import { hydrateShadowRoots as querySelectorHydration } from '../_implementation/queryselectorall.js';
const implausiblyLongTimeToIndicateFailure = 9 * 1000 * 1000;
function benchmark(hydrateMethod) {
let hydrateShadowRoots;
if (hydrateMethod === 'manualWalk') {
hydrateShadowRoots = manualWalkHydration;
} else if (hydrateMethod === 'querySelector') {
hydrateShadowRoots = querySelectorHydration;
} else {
return implausiblyLongTimeToIndicateFailure;
}
const html = `
<div>
<template shadowrootmode="open">
<div>Hello world</div>
</template>
</div>
`;
const start = performance.now();
document.body.innerHTML = html.repeat(1000);
hydrateShadowRoots(document.body);
const duration = performance.now() - start;
if (document.querySelector('template') === null) {
return duration;
} else {
// hydration failed, still see templates in the document!
return implausiblyLongTimeToIndicateFailure;
}
}
window.tachometerResult = benchmark(window.location.search.slice(1));
</script>
</body>
</html>