mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
fde30a15e6
PR-URL: https://github.com/nodejs/node/pull/54254 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fs = require('fs');
|
|
const assert = require('assert');
|
|
const tmpdir = require('../../test/common/tmpdir');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['invalid', 'valid'],
|
|
n: [2e3],
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
switch (type) {
|
|
case 'invalid': {
|
|
let hasError = false;
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
try {
|
|
fs.renameSync(tmpdir.resolve(`.non-existing-file-${i}`), tmpdir.resolve(`.new-file-${i}`));
|
|
} catch {
|
|
hasError = true;
|
|
}
|
|
}
|
|
bench.end(n);
|
|
assert.ok(hasError);
|
|
break;
|
|
}
|
|
case 'valid': {
|
|
tmpdir.refresh();
|
|
for (let i = 0; i < n; i++) {
|
|
fs.writeFileSync(tmpdir.resolve(`.existing-file-${i}`), 'bench', 'utf8');
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
fs.renameSync(
|
|
tmpdir.resolve(`.existing-file-${i}`),
|
|
tmpdir.resolve(`.new-existing-file-${i}`),
|
|
);
|
|
}
|
|
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
default:
|
|
throw new Error('Invalid type');
|
|
}
|
|
}
|