-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.js
More file actions
35 lines (25 loc) · 651 Bytes
/
Copy patha.js
File metadata and controls
35 lines (25 loc) · 651 Bytes
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
const { performance, PerformanceObserver } = require('perf_hooks')
function someFunction1 () {
let counter = 0
while (counter <= 10) {
// console.log(counter)
counter += 1
}
}
function someFunction2 () {
let counter = 0
while (counter <= 11) {
// console.log(counter)
counter += 1
}
}
let wrapped1 = performance.timerify(someFunction1)
let wrapped2 = performance.timerify(someFunction2)
let obs = new PerformanceObserver(list => {
console.log(list.getEntries()[0].duration)
// obs.disconnect()
})
obs.observe({ entryTypes: ['function'] })
// A performance timeline entry will be created
wrapped1()
wrapped2()