0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/benchmark/fs/bench-opendirSync.js
Antoine du Hamel d9540b51eb
fs: remove dirent.path
PR-URL: https://github.com/nodejs/node/pull/55548
Fixes: https://github.com/nodejs/node/issues/55538
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2024-11-15 00:18:05 +01:00

44 lines
955 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.parentPath, 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);
}