node/benchmark/permission/permission-processhas-fs-read.js
Rafael Gonzaga 834316d541
benchmark: add no-warnings to process.has bench
PR-URL: https://github.com/nodejs/node/pull/55159
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-09-30 20:27:39 +00:00

41 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common.js');
const path = require('path');
const configs = {
n: [1e5],
concurrent: [1, 10],
};
const rootPath = path.resolve(__dirname, '../../..');
const options = {
flags: [
'--experimental-permission',
`--allow-fs-read=${rootPath}`,
'--allow-child-process',
'--no-warnings',
],
};
const bench = common.createBenchmark(main, configs, options);
// This is a naive benchmark and might not demonstrate real-world use cases.
// New benchmarks will be created once the permission model config is available
// through a config file.
async function main(conf) {
const benchmarkDir = path.join(__dirname, '../..');
bench.start();
for (let i = 0; i < conf.n; i++) {
// Valid file in a sequence of denied files
process.permission.has('fs.read', benchmarkDir + '/valid-file');
// Denied file
process.permission.has('fs.read', __filename);
// Valid file a granted directory
process.permission.has('fs.read', '/tmp/example');
}
bench.end(conf.n);
}