11cb0ef41Sopenharmony_ci// Tests the impact on eager operations required for policies affecting 21cb0ef41Sopenharmony_ci// general startup, does not test lazy operations 31cb0ef41Sopenharmony_ci'use strict'; 41cb0ef41Sopenharmony_ciconst common = require('../common.js'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst configs = { 71cb0ef41Sopenharmony_ci n: [1024], 81cb0ef41Sopenharmony_ci}; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst options = { 111cb0ef41Sopenharmony_ci flags: ['--expose-internals'], 121cb0ef41Sopenharmony_ci}; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, configs, options); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction main(conf) { 171cb0ef41Sopenharmony_ci const hash = (str, algo) => { 181cb0ef41Sopenharmony_ci const hash = require('crypto').createHash(algo); 191cb0ef41Sopenharmony_ci return hash.update(str).digest('base64'); 201cb0ef41Sopenharmony_ci }; 211cb0ef41Sopenharmony_ci const resources = Object.fromEntries( 221cb0ef41Sopenharmony_ci // Simulate graph of 1k modules 231cb0ef41Sopenharmony_ci Array.from({ length: 1024 }, (_, i) => { 241cb0ef41Sopenharmony_ci return [`./_${i}`, { 251cb0ef41Sopenharmony_ci integrity: `sha256-${hash(`// ./_${i}`, 'sha256')}`, 261cb0ef41Sopenharmony_ci dependencies: Object.fromEntries(Array.from({ 271cb0ef41Sopenharmony_ci // Average 3 deps per 4 modules 281cb0ef41Sopenharmony_ci length: Math.floor((i % 4) / 2), 291cb0ef41Sopenharmony_ci }, (_, ii) => { 301cb0ef41Sopenharmony_ci return [`_${ii}`, `./_${i - ii}`]; 311cb0ef41Sopenharmony_ci })), 321cb0ef41Sopenharmony_ci }]; 331cb0ef41Sopenharmony_ci }), 341cb0ef41Sopenharmony_ci ); 351cb0ef41Sopenharmony_ci const json = JSON.parse(JSON.stringify({ resources }), (_, o) => { 361cb0ef41Sopenharmony_ci if (o && typeof o === 'object') { 371cb0ef41Sopenharmony_ci Reflect.setPrototypeOf(o, null); 381cb0ef41Sopenharmony_ci Object.freeze(o); 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci return o; 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci const { Manifest } = require('internal/policy/manifest'); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci bench.start(); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci for (let i = 0; i < conf.n; i++) { 471cb0ef41Sopenharmony_ci new Manifest(json, 'file://benchmark/policy-relative'); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci bench.end(conf.n); 511cb0ef41Sopenharmony_ci} 52