-
-
Save willmendesneto/c0abc2a0c8d0ced80c94fde7ac73e44e to your computer and use it in GitHub Desktop.
Using User Timing API in Nodejs via perf_hooks package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { performance, PerformanceObserver } = require('perf_hooks'); | |
const marker = 'my-marker'; | |
const observer = new PerformanceObserver((list) => { | |
// Using `console.log()` to display metrics for `my-marker` | |
// After that, this observer will be disconnected | |
console.log(list.getEntries().find(i => i.name === marker)); | |
observer.disconnect(); | |
}); | |
observer.observe({ entryTypes: ['measure'] }); | |
// Starting the marker | |
performance.mark(marker); | |
setTimeout(() => { | |
// Calling the marker for comparison | |
performance.mark(`${marker}-end`); | |
setTimeout(() => { | |
performance.measure(marker, marker, `${marker}-end`); | |
}, 1000); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment