mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
571ecbf992
PR-URL: https://github.com/nodejs/node/pull/49705 Refs: https://github.com/nodejs/performance/issues/106 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
44 lines
949 B
JavaScript
44 lines
949 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const tmpdir = require('../../test/common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
const testFiles = fs.readdirSync('test', { withFileTypes: true })
|
|
.filter((f) => f.isDirectory())
|
|
.map((f) => path.join(f.path, f.name));
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['existing', 'non-existing'],
|
|
n: [1e3],
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
let files;
|
|
|
|
switch (type) {
|
|
case 'existing':
|
|
files = testFiles;
|
|
break;
|
|
case 'non-existing':
|
|
files = [tmpdir.resolve(`.non-existing-file-${Date.now()}`)];
|
|
break;
|
|
default:
|
|
new Error('Invalid type');
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
for (let j = 0; j < files.length; j++) {
|
|
try {
|
|
const dir = fs.opendirSync(files[j]);
|
|
dir.closeSync();
|
|
} catch {
|
|
// do nothing
|
|
}
|
|
}
|
|
}
|
|
bench.end(n);
|
|
}
|