Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Created Mar 29, 2021
Embed
What would you like to do?
Using User Timing API in Nodejs via perf_hooks package
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