Skip to content

Commit

Permalink
Merge pull request #437 from huntharo/issue-436/fix-perf-memory-report
Browse files Browse the repository at this point in the history
Issue-436 - Fix perf test memory reporting on `node@^20.3.0` on Mac
  • Loading branch information
derduher authored May 23, 2024
2 parents dbbdbd9 + a69ad31 commit c9d8ff9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ function delay(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}

function normalizedRss() {
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
const isMac = process.platform === 'darwin';
// Node 20.3.0 included libuv 1.45.0, which fixes
// Mac reporting of `maxRSS` to be `KB` insteead of `bytes`.
// All other platforms were returning `KB` before.
const divisor = isMac && nodeVersion < 20.3 ? 1024 ** 2 : 1024;
return process.resourceUsage().maxRSS / divisor;
}

async function batch(durations, runNum, fn) {
for (let i = 0; i < batchSize; i++) {
const start = process.resourceUsage().userCPUTime;
Expand All @@ -77,7 +87,7 @@ async function batch(durations, runNum, fn) {
}
let duration;
if (measureMemory) {
duration = (process.resourceUsage().maxRSS / 1024 ** 2) | 0;
duration = normalizedRss() | 0;
} else {
duration = ((process.resourceUsage().userCPUTime - start) / 1e3) | 0;
}
Expand Down

0 comments on commit c9d8ff9

Please sign in to comment.