-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
110 lines (94 loc) · 2.78 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>raf-perf by Damien Seguin (https://github.com/dmnsgn)</title>
<style>
:root {
--color-dark: #404040;
--color-light: #f2f2f2;
--color-accent: #fd5e62;
}
body {
margin: 0;
overflow: hidden;
overscroll-behavior: none;
font-family: sans-serif;
color: var(--color-dark);
background-color: var(--color-light);
}
main {
padding: 0 20px;
max-width: 600px;
margin: auto;
}
.RectCount {
color: var(--color-accent);
font-size: 30px;
font-weight: bold;
}
</style>
</head>
<body>
<main>
<h1>raf-perf</h1>
<p class="RectCount"></p>
</main>
<script async src="web_modules/es-module-shims.js" type="module"></script>
<script src="web_modules/import-map.json" type="importmap-shim"></script>
<script type="module-shim">
import RafPerf from "./index.js";
import createCanvasContext from "canvas-context";
const width = 600;
const { context, canvas } = createCanvasContext("2d", {
width,
height: 600,
alpha: false,
});
document.querySelector("main").appendChild(canvas);
const maxRectCount = 4500;
let rectCount = maxRectCount / 2;
const RectCountElement = document.querySelector(".RectCount");
const engine = new RafPerf({
// fps: 120,
performances: {
enabled: true,
samplesCount: 200,
sampleDuration: 4000,
},
});
const color = window
.getComputedStyle(document.documentElement)
.getPropertyValue("--color-accent");
engine.on(RafPerf.TickEvent, (dt) => {
context.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < rectCount; i++) {
context.shadowColor = color;
context.shadowBlur = 10;
context.fillStyle = color;
context.fillRect(
40 + (i % width) * 0.5,
40 + Math.floor(i / width) * 10,
200,
5
);
}
RectCountElement.innerText = `${rectCount} rect with shadowBlur`;
});
engine.on(RafPerf.PerfEvent, (ratio) => {
if (!ratio) return;
console.log(`Performance ratio: ${ratio}`);
if (ratio < 0.9) {
console.log("Too many draws");
rectCount -= 50;
} else if (ratio >= 0.9 && rectCount < maxRectCount) {
console.log("Draw more");
rectCount += 100;
}
});
engine.start();
</script>
</body>
</html>