/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
benchmark/fs/bench-existsSync.js
38 строк
833 B
Yagiz Nizipli
fs: improve error performance of sync methods
17 сен 2023, 23:42
Не верифицирован
17 сен 2023, 23:42
7e12d0e
Код
Авторство
О чём код?
'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); }