Skip to content

Commit 9827c2e

Browse files
committed
Updated memory benchmark
1 parent 3f694ee commit 9827c2e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

benchmarks/node/memory-benchmark.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/usr/bin/env node
2+
3+
// Note: getting replicable results from this script requires:
4+
// (1) Running with the `--expose-gc` flag,
5+
// (2) adding `global.gc()` within the `index.js` file
6+
// to force garbage collection within each worker after each iteration.
7+
28
const path = require('path');
39
const { createWorker, createScheduler } = require('../../src');
410

@@ -43,19 +49,25 @@ const workerGen = async () => {
4349
const time1 = Date.now();
4450
const promises = [];
4551
for (let j = 0; j < 10; j++) {
46-
promises.push(scheduler.addJob('recognize', file));
52+
// Results are purposefully not saved as this would increase memory usage over time.
53+
promises.push(scheduler.addJob('recognize', file).then(() => (true)));
4754
}
4855
// eslint-disable-next-line no-await-in-loop
4956
await Promise.all(promises);
5057

51-
if (global.gc) global.gc();
52-
5358
const time2 = Date.now();
5459
const timeDif = (time2 - time1) / 1e3;
5560
iterationTime += timeDif;
5661
}
62+
63+
if (global.gc) global.gc();
64+
5765
// Print memory stats and time after each iteration
5866
console.log(getMemoryRow(i + 1, process.memoryUsage(), iterationTime));
5967
}
68+
69+
if (global.gc) global.gc();
70+
// require('v8').writeHeapSnapshot();
71+
6072
scheduler.terminate();
6173
})();

0 commit comments

Comments
 (0)