1// Tests the impact on eager operations required for policies affecting 2// general startup, does not test lazy operations 3'use strict'; 4const common = require('../common.js'); 5 6const configs = { 7 n: [1024], 8}; 9 10const options = { 11 flags: ['--expose-internals'], 12}; 13 14const bench = common.createBenchmark(main, configs, options); 15 16function main(conf) { 17 const hash = (str, algo) => { 18 const hash = require('crypto').createHash(algo); 19 return hash.update(str).digest('base64'); 20 }; 21 const resources = Object.fromEntries( 22 // Simulate graph of 1k modules 23 Array.from({ length: 1024 }, (_, i) => { 24 return [`./_${i}`, { 25 integrity: `sha256-${hash(`// ./_${i}`, 'sha256')}`, 26 dependencies: Object.fromEntries(Array.from({ 27 // Average 3 deps per 4 modules 28 length: Math.floor((i % 4) / 2), 29 }, (_, ii) => { 30 return [`_${ii}`, `./_${i - ii}`]; 31 })), 32 }]; 33 }), 34 ); 35 const json = JSON.parse(JSON.stringify({ resources }), (_, o) => { 36 if (o && typeof o === 'object') { 37 Reflect.setPrototypeOf(o, null); 38 Object.freeze(o); 39 } 40 return o; 41 }); 42 const { Manifest } = require('internal/policy/manifest'); 43 44 bench.start(); 45 46 for (let i = 0; i < conf.n; i++) { 47 new Manifest(json, 'file://benchmark/policy-relative'); 48 } 49 50 bench.end(conf.n); 51} 52