node/benchmark/fs/bench-readdirSync.js
Joyee Cheung ca51b9471c benchmark: add dir and withFileTypes option readdir benchmarks
PR-URL: https://github.com/nodejs/node/pull/24125
Refs: 0483e9a9ab
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2018-11-08 15:01:14 -08:00

23 lines
506 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const bench = common.createBenchmark(main, {
n: [10],
dir: [ 'lib', 'test/parallel'],
withFileTypes: ['true', 'false']
});
function main({ n, dir, withFileTypes }) {
withFileTypes = withFileTypes === 'true';
const fullPath = path.resolve(__dirname, '../../', dir);
bench.start();
for (var i = 0; i < n; i++) {
fs.readdirSync(fullPath, { withFileTypes });
}
bench.end(n);
}