Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,39 @@
'use strict';
const fs = require('fs');
const path = require('path');
const common = require('../common.js');
const { strictEqual } = require('assert');
const tmpdir = require('../../test/common/tmpdir');
const benchmarkDirectory = tmpdir.resolve('benchmark-esm-parse');
const bench = common.createBenchmark(main, {
n: [1e2],
});
async function main({ n }) {
tmpdir.refresh();
fs.mkdirSync(benchmarkDirectory);
let sampleSource = 'try {\n';
for (let i = 0; i < 1000; i++) {
sampleSource += 'sample.js(() => file = /test/);\n';
}
sampleSource += '} catch {}\nexports.p = 5;\n';
for (let i = 0; i < n; i++) {
const sampleFile = path.join(benchmarkDirectory, `sample${i}.js`);
fs.writeFileSync(sampleFile, sampleSource);
}
bench.start();
for (let i = 0; i < n; i++) {
const sampleFile = path.join(benchmarkDirectory, `sample${i}.js`);
const m = await import('file:' + sampleFile);
strictEqual(m.p, 5);
}
bench.end(n);
tmpdir.refresh();
}

View File

@ -0,0 +1,36 @@
'use strict';
// This benchmarks the cost of running `containsModuleSyntax` on a CommonJS module being imported.
// We use the TypeScript fixture because it's a very large CommonJS file with no ESM syntax: the worst case.
const common = require('../common.js');
const tmpdir = require('../../test/common/tmpdir.js');
const fs = require('node:fs');
const bench = common.createBenchmark(main, {
type: ['with-package-json', 'without-package-json'],
n: [1e4],
});
async function main({ n, type }) {
tmpdir.refresh();
fs.mkdirSync(tmpdir.resolve('bench'));
let loader = '';
const modules = [];
for (let i = 0; i < n; i++) {
const url = tmpdir.fileURL('bench', `mod${i}.js`);
fs.writeFileSync(url, `const foo${i} = ${i};\nexport { foo${i} };\n`);
loader += `import { foo${i} } from './mod${i}.js';\n`;
modules.push(url);
}
const loaderURL = tmpdir.fileURL('bench', 'load.js');
fs.writeFileSync(loaderURL, loader);
if (type === 'with-package-json') {
fs.writeFileSync(tmpdir.resolve('bench', 'package.json'), '{ "type": "module" }');
}
bench.start();
await import(loaderURL);
bench.end(n);
}

View File

@ -0,0 +1,52 @@
// Tests the impact on eager operations required for policies affecting
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const common = require('../common.js');
const tmpdir = require('../../test/common/tmpdir.js');
const { pathToFileURL } = require('node:url');
const benchmarkDirectory = tmpdir.resolve('benchmark-import-meta-resolve');
const configs = {
n: [1e4],
packageJsonUrl: [
'node_modules/test/package.json',
],
packageConfigMain: ['', './index.js'],
resolvedFile: [
'node_modules/test/index.js',
'node_modules/test/index.json',
'node_modules/test/index.node',
'node_modules/non-exist',
],
};
const options = {
flags: ['--expose-internals'],
};
const bench = common.createBenchmark(main, configs, options);
function main(conf) {
const { legacyMainResolve } = require('internal/modules/esm/resolve');
tmpdir.refresh();
fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'test'), { recursive: true });
fs.writeFileSync(path.join(benchmarkDirectory, conf.resolvedFile), '\n');
const packageJsonUrl = pathToFileURL(conf.packageJsonUrl);
const packageConfigMain = { main: conf.packageConfigMain };
bench.start();
for (let i = 0; i < conf.n; i++) {
try {
legacyMainResolve(packageJsonUrl, packageConfigMain, undefined);
} catch { /* empty */ }
}
bench.end(conf.n);
}

View File

@ -0,0 +1,50 @@
// Tests the impact on eager operations required for policies affecting
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const common = require('../common.js');
const tmpdir = require('../../test/common/tmpdir.js');
const { pathToFileURL } = require('node:url');
const benchmarkDirectory = tmpdir.resolve('benchmark-import-meta-resolve');
const parentURL = pathToFileURL(path.join(benchmarkDirectory, 'entry-point.js'));
const configs = {
n: [1e3],
specifier: [
'./relative-existing.js',
'./relative-nonexistent.js',
'unprefixed-existing',
'unprefixed-nonexistent',
'node:prefixed-nonexistent',
'node:os',
],
};
const options = {
flags: ['--expose-internals'],
};
const bench = common.createBenchmark(main, configs, options);
function main(conf) {
const { defaultResolve } = require('internal/modules/esm/resolve');
tmpdir.refresh();
fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing'), { recursive: true });
fs.writeFileSync(path.join(benchmarkDirectory, 'node_modules', 'unprefixed-existing', 'index.js'), '\n');
fs.writeFileSync(path.join(benchmarkDirectory, 'relative-existing.js'), '\n');
bench.start();
for (let i = 0; i < conf.n; i++) {
try {
defaultResolve(conf.specifier, { parentURL });
} catch { /* empty */ }
}
bench.end(conf.n);
}

View File

@ -0,0 +1,43 @@
// Tests the impact on eager operations required for policies affecting
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const common = require('../common.js');
const tmpdir = require('../../test/common/tmpdir.js');
const benchmarkDirectory = tmpdir.fileURL('benchmark-import');
const configs = {
n: [1e3],
specifier: [
'data:text/javascript,{i}',
'./relative-existing.js',
'./relative-nonexistent.js',
'node:prefixed-nonexistent',
'node:os',
],
};
const options = {
flags: ['--expose-internals'],
};
const bench = common.createBenchmark(main, configs, options);
async function main(conf) {
tmpdir.refresh();
fs.mkdirSync(benchmarkDirectory, { recursive: true });
fs.writeFileSync(new URL('./relative-existing.js', benchmarkDirectory), '\n');
bench.start();
for (let i = 0; i < conf.n; i++) {
try {
await import(new URL(conf.specifier.replace('{i}', i), benchmarkDirectory));
} catch { /* empty */ }
}
bench.end(conf.n);
}

View File

@ -0,0 +1,37 @@
'use strict';
const path = require('path');
const { pathToFileURL } = require('url');
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1000],
valuesToRead: [
'dirname-and-filename',
'dirname',
'filename',
],
});
const fixtureDir = path.resolve(__filename, '../../fixtures');
const fixtureDirURL = pathToFileURL(fixtureDir);
async function load(array, n, valuesToRead) {
for (let i = 0; i < n; i++) {
array[i] = await import(`${fixtureDirURL}/import-meta-${valuesToRead}.mjs?i=${i}`);
}
return array;
}
function main({ n, valuesToRead }) {
const array = [];
for (let i = 0; i < n; ++i) {
array.push({ dirname: '', filename: '', i: 0 });
}
bench.start();
load(array, n, valuesToRead).then((arr) => {
bench.end(n);
if (valuesToRead.includes('dirname')) assert.strictEqual(arr[n - 1].dirname, fixtureDir);
if (valuesToRead.includes('filename')) assert.strictEqual(arr[n - 1].filename, path.join(fixtureDir, `import-meta-${valuesToRead}.mjs`));
});
}

View File

@ -0,0 +1,79 @@
'use strict';
const common = require('../common');
const fs = require('fs');
const tmpdir = require('../../test/common/tmpdir');
const path = require('path');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: ['all', 'access', 'load'],
exports: ['default', 'named'],
n: [1000],
}, {
flags: ['--experimental-require-module', '--no-warnings'],
});
function prepare(count, useDefault) {
tmpdir.refresh();
const dir = tmpdir.resolve('modules');
fs.mkdirSync(dir, { recursive: true });
let mainSource = '';
let useSource = 'exports.access = function() { return 0';
for (let i = 0; i < count; ++i) {
let modSource = `const value${i} = 1;\n`;
if (useDefault) {
modSource += `export default { value${i} }\n`;
} else {
modSource += `export { value${i} };\n`;
}
const filename = `mod${i}.mjs`;
fs.writeFileSync(
path.resolve(dir, filename),
modSource,
'utf8',
);
mainSource += `const mod${i} = require('./modules/${filename}');\n`;
if (useDefault) {
useSource += ` + mod${i}.default.value${i}`;
} else {
useSource += ` + mod${i}.value${i}`;
}
}
useSource += '; };\n';
const script = tmpdir.resolve('main.js');
fs.writeFileSync(script, mainSource + useSource, 'utf8');
return script;
}
function main({ n, exports, type }) {
const script = prepare(n, exports === 'default');
switch (type) {
case 'all': {
bench.start();
const result = require(script).access();
bench.end(n);
assert.strictEqual(result, n);
break;
}
case 'access': {
const { access } = require(script);
bench.start();
let result = access();
for (let i = 0; i < 99; ++i) {
result = access();
}
bench.end(n * 100);
assert.strictEqual(result, n);
break;
}
case 'load': {
bench.start();
const { access } = require(script);
bench.end(n);
const result = access();
assert.strictEqual(result, n);
break;
}
}
}