-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformance.html
41 lines (41 loc) · 2.16 KB
/
performance.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>performance</title>
</head>
<body>
<div id="js-loop"></div>
<div id="dom-loop"></div>
<script>
const arr = new Array(1).fill(
10000000021212100012918271927192791291729121210000031231000000000217281728172811212100012918271927192791291729121210000031231000000000217281728172121210001291827192719279129172912121000003123100000000021728172817212121000129182719271927912917291212100000312310000000002172817281721212100012918271927192791291729121210000031231000000000217281728172121210001291827192719279129172912121000003123100000000021728172817212121000129182719271927912917291212100000312310000000002172817281727281781000000000000000000000000000000000000000000000000000000000000000000000000
)
let timer1 = performance.now()
for (let i = 0; i < arr.length; i++) {
arr[i] =
i *
1000003128172817218000000313121210312817281721800000031312121211000031281728172180000003131212121100003128172817218000000313121212110000312817281721800000031312121211000031281728172180000003131212121100003128172817218000000313121212110000312817281721800000031312121211000031281728172180000003131212121100003128172817218000000313121212110000312817281721800000031312121211000211000000 *
121212121028192 *
1212131 +
(1219281 *
1218201821031281728172180000003131212121100003128172817218000000313121212110000312817281721800000031312121211000212108219) /
12182192891289182918
}
let timer2 = performance.now()
console.log(`js loop: ${timer2 - timer1}ms`)
document.getElementById('js-loop').textContent = `js loop: ${timer2 - timer1}ms`
for (let i = 0; i < arr.length; i++) {
const span = document.createElement('span')
span.textContent = i
document.body.appendChild(span)
}
let timer3 = performance.now()
console.log(`dom loop: ${timer3 - timer2}ms`)
document.getElementById('dom-loop').textContent = `dom loop: ${timer3 - timer2}ms`
</script>
</body>
</html>