mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 11:29:26 +00:00

* Update the user timing implementation to conform to User Timing Level 3. * Reimplement user timing and timerify with pure JavaScript implementations * Simplify the C++ implementation for gc and http2 perf * Runtime deprecate additional perf entry properties in favor of the standard detail argument * Disable the `buffered` option on PerformanceObserver, all entries are queued and dispatched on setImmediate. Only entries with active observers are buffered. * This does remove the user timing and timerify trace events. Because the trace_events are still considered experimental, those can be removed without a deprecation cycle. They are removed to improve performance and reduce complexity. Old: `perf_hooks/usertiming.js n=100000: 92,378.01249733355` New: perf_hooks/usertiming.js n=100000: 270,393.5280638482` PR-URL: https://github.com/nodejs/node/pull/37136 Refs: https://github.com/nodejs/diagnostics/issues/464 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
41 lines
727 B
JavaScript
41 lines
727 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const {
|
|
PerformanceObserver,
|
|
performance: {
|
|
timerify,
|
|
},
|
|
} = require('perf_hooks');
|
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
|
setTimeout: sleep
|
|
} = require('timers/promises');
|
|
|
|
let check = false;
|
|
|
|
async function doIt() {
|
|
await sleep(100);
|
|
check = true;
|
|
return check;
|
|
}
|
|
|
|
const obs = new PerformanceObserver(common.mustCall((list) => {
|
|
const entry = list.getEntries()[0];
|
|
assert.strictEqual(entry.name, 'doIt');
|
|
assert(entry.duration > 100);
|
|
assert(check);
|
|
obs.disconnect();
|
|
}));
|
|
|
|
obs.observe({ type: 'function' });
|
|
|
|
const timerified = timerify(doIt);
|
|
|
|
const res = timerified();
|
|
assert(res instanceof Promise);
|
|
res.then(common.mustCall(assert));
|