-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf_hooks: reduce overhead of new performance_entries
PR-URL: #49803 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
- Loading branch information
Showing
2 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const common = require('../common.js'); | ||
|
||
const { | ||
PerformanceObserver, | ||
performance, | ||
} = require('perf_hooks'); | ||
|
||
function randomFn() { | ||
return Math.random(); | ||
} | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e5], | ||
observe: ['function'], | ||
}); | ||
|
||
let _result; | ||
|
||
function main({ n, observe }) { | ||
const obs = new PerformanceObserver(() => { | ||
bench.end(n); | ||
}); | ||
obs.observe({ entryTypes: [observe], buffered: true }); | ||
|
||
const timerfied = performance.timerify(randomFn); | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) | ||
_result = timerfied(); | ||
|
||
// Avoid V8 deadcode (elimination) | ||
assert.ok(_result); | ||
} |
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