doc: add esm examples to `node:perf_hooks`
This PR adds the ESM counterparts of the CJS examples for the Performance measurement APIs documentation.
There is one particular example in which I'd like to get a more in depth feedback, it's the Measuring how long it takes to load dependencies example.
I've done it this way:
import { performance, PerformanceObserver } from 'node:perf_hooks';
// Activate the observer
const obs = new PerformanceObserver((list) => {
const entries = list.getEntries();
entries.forEach((entry) => {
console.log(`import('${entry[0]}')`, entry.duration);
});
performance.clearMarks();
performance.clearMeasures();
obs.disconnect();
});
obs.observe({ entryTypes: ['function'], buffered: true });
const timedImport = performance.timerify(async (module) => {
return await import(module);
});
await timedImport('some-module');
(you can try it by replacing 'some-module' with, let's say, 'node:child_process')
Which gets the job done, but would you agree it's a correct counterpart for its CJS example? I feel I might lack more deep knowledge about the differences between require and import.
Thanks in advance and as always best regards!
@nodejs/loaders for the question.
hello @lpinca do you know of anyone I could maybe tag to get a review on this PR? just so it doesn't get stalled :blush:
thanks in advance! :raised_hands:
Landed in 96cd2a6ec32917f430444904ab13239564480b1a