From a69ad31b6fda66c0e92bdad9e6320a1b0261aa11 Mon Sep 17 00:00:00 2001 From: Harold Hunt Date: Wed, 22 May 2024 13:41:18 -0400 Subject: [PATCH] Issue-436 - Fix perf test memory reporting --- tests/perf.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/perf.js b/tests/perf.js index a86bbe9..e0aa759 100755 --- a/tests/perf.js +++ b/tests/perf.js @@ -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; @@ -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; }