mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
7e12d0e16d
PR-URL: https://github.com/nodejs/node/pull/49593 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
39 lines
833 B
JavaScript
39 lines
833 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fs = require('fs');
|
|
const tmpdir = require('../../test/common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
const tmpfile = tmpdir.resolve(`.existing-file-${process.pid}`);
|
|
fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['existing', 'non-existing', 'non-flat-existing'],
|
|
n: [1e6],
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
let path;
|
|
|
|
switch (type) {
|
|
case 'existing':
|
|
path = __filename;
|
|
break;
|
|
case 'non-flat-existing':
|
|
path = tmpfile;
|
|
break;
|
|
case 'non-existing':
|
|
path = tmpdir.resolve(`.non-existing-file-${process.pid}`);
|
|
break;
|
|
default:
|
|
new Error('Invalid type');
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
fs.existsSync(path);
|
|
}
|
|
bench.end(n);
|
|
}
|