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,57 @@
'use strict';
const { createBenchmark } = require('../common.js');
const { format } = require('util');
const methods = [
'restAndSpread',
'argumentsAndApply',
'restAndApply',
'predefined',
];
const bench = createBenchmark(main, {
method: methods,
n: [1e6],
});
function usingRestAndSpread(...args) {
format(...args);
}
function usingRestAndApply(...args) {
format.apply(null, args);
}
function usingArgumentsAndApply() {
format.apply(null, arguments);
}
function usingPredefined() {
format('part 1', 'part', 2, 'part 3', 'part', 4);
}
function main({ n, method, args }) {
let fn;
switch (method) {
case 'restAndSpread':
fn = usingRestAndSpread;
break;
case 'restAndApply':
fn = usingRestAndApply;
break;
case 'argumentsAndApply':
fn = usingArgumentsAndApply;
break;
case 'predefined':
fn = usingPredefined;
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
bench.start();
for (let i = 0; i < n; i++)
fn('part 1', 'part', 2, 'part 3', 'part', 4);
bench.end(n);
}

View File

@ -0,0 +1,40 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [100000],
}, {
flags: ['--expose-internals'],
});
function main({ n }) {
let FreeList = require('internal/freelist');
if (FreeList.FreeList)
FreeList = FreeList.FreeList;
const poolSize = 1000;
const list = new FreeList('test', poolSize, Object);
let j;
const used = [];
// First, alloc `poolSize` items
for (j = 0; j < poolSize; j++) {
used.push(list.alloc());
}
bench.start();
for (let i = 0; i < n; i++) {
// Return all the items to the pool
for (j = 0; j < poolSize; j++) {
list.free(used[j]);
}
// Re-alloc from pool
for (j = 0; j < poolSize; j++) {
list.alloc();
}
}
bench.end(n);
}

View File

@ -0,0 +1,26 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
type: ['ascii', 'mixed', 'emojiseq', 'fullwidth'],
n: [10e4],
}, {
flags: ['--expose-internals'],
});
function main({ n, type }) {
const { getStringWidth } = require('internal/util/inspect');
const str = ({
ascii: 'foobar'.repeat(100),
mixed: 'foo'.repeat(100) + '😀' + 'bar'.repeat(100),
emojiseq: '👨‍👨‍👧‍👦👨‍👩‍👦‍👦👨‍👩‍👧‍👧👩‍👩‍👧‍👦'.repeat(10),
fullwidth: '你好'.repeat(150),
})[type];
bench.start();
for (let j = 0; j < n; j += 1)
getStringWidth(str);
bench.end(n);
}

View File

@ -0,0 +1,82 @@
'use strict';
/* eslint-disable dot-notation */
const common = require('../common.js');
const bench = common.createBenchmark(main, {
method: ['property', 'string', 'variable', 'symbol'],
n: [1e9],
});
function runProperty(n) {
const object = {};
bench.start();
for (let i = 0; i < n; i++) {
object.p1 = 21;
object.p2 = 21;
object.p1 += object.p2;
}
bench.end(n);
}
function runString(n) {
const object = {};
bench.start();
for (let i = 0; i < n; i++) {
object['p1'] = 21;
object['p2'] = 21;
object['p1'] += object['p2'];
}
bench.end(n);
}
function runVariable(n) {
const object = {};
const var1 = 'p1';
const var2 = 'p2';
bench.start();
for (let i = 0; i < n; i++) {
object[var1] = 21;
object[var2] = 21;
object[var1] += object[var2];
}
bench.end(n);
}
function runSymbol(n) {
const object = {};
const symbol1 = Symbol('p1');
const symbol2 = Symbol('p2');
bench.start();
for (let i = 0; i < n; i++) {
object[symbol1] = 21;
object[symbol2] = 21;
object[symbol1] += object[symbol2];
}
bench.end(n);
}
function main({ n, method }) {
switch (method) {
case 'property':
runProperty(n);
break;
case 'string':
runString(n);
break;
case 'variable':
runVariable(n);
break;
case 'symbol':
runSymbol(n);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}

59
benchmark/misc/print.js Normal file
View File

@ -0,0 +1,59 @@
'use strict';
const common = require('../common.js');
const { spawn } = require('child_process');
const bench = common.createBenchmark(main, {
dur: [1],
code: ['1', '"string"', 'process.versions', 'process'],
});
function spawnProcess(code) {
const cmd = process.execPath || process.argv[0];
const argv = ['-p', code];
return spawn(cmd, argv);
}
function start(state, code, bench, getNode) {
const node = getNode(code);
let stdout = '';
let stderr = '';
node.stdout.on('data', (data) => {
stdout += data;
});
node.stderr.on('data', (data) => {
stderr += data;
});
node.on('exit', (code) => {
if (code !== 0) {
console.error('------ stdout ------');
console.error(stdout);
console.error('------ stderr ------');
console.error(stderr);
throw new Error(`Error during node startup, exit code ${code}`);
}
state.throughput++;
if (state.go) {
start(state, code, bench, getNode);
} else {
bench.end(state.throughput);
}
});
}
function main({ dur, code }) {
const state = {
go: true,
throughput: 0,
};
setTimeout(() => {
state.go = false;
}, dur * 1000);
bench.start();
start(state, code, bench, spawnProcess);
}

View File

@ -0,0 +1,79 @@
'use strict';
const common = require('../common.js');
let icu;
try {
icu = common.binding('icu');
} catch {
// Continue regardless of error.
}
const punycode = require('punycode');
const bench = common.createBenchmark(main, {
method: ['punycode'].concat(icu !== undefined ? ['icu'] : []),
n: [1024],
val: [
'افغانستا.icom.museum',
'الجزائر.icom.museum',
'österreich.icom.museum',
'বাংলাদেশ.icom.museum',
'беларусь.icom.museum',
'belgië.icom.museum',
'българия.icom.museum',
'تشادر.icom.museum',
'中国.icom.museum',
'القمر.icom.museum',
'κυπρος.icom.museum',
'českárepublika.icom.museum',
'مصر.icom.museum',
'ελλάδα.icom.museum',
'magyarország.icom.museum',
'ísland.icom.museum',
'भारत.icom.museum',
'ايران.icom.museum',
'éire.icom.museum',
'איקו״ם.ישראל.museum',
'日本.icom.museum',
'الأردن.icom.museum',
],
});
function usingPunycode(val) {
punycode.toUnicode(punycode.toASCII(val));
}
function usingICU(val) {
icu.toUnicode(icu.toASCII(val));
}
function runPunycode(n, val) {
for (let i = 0; i < n; i++)
usingPunycode(val);
bench.start();
for (let i = 0; i < n; i++)
usingPunycode(val);
bench.end(n);
}
function runICU(n, val) {
bench.start();
for (let i = 0; i < n; i++)
usingICU(val);
bench.end(n);
}
function main({ n, val, method }) {
switch (method) {
case 'punycode':
runPunycode(n, val);
break;
case 'icu':
if (icu !== undefined) {
runICU(n, val);
break;
}
// fallthrough
default:
throw new Error(`Unexpected method "${method}"`);
}
}

View File

@ -0,0 +1,55 @@
'use strict';
const common = require('../common.js');
const { spawnSync } = require('child_process');
const { existsSync } = require('fs');
const path = require('path');
// This benchmarks the startup of various CLI tools that are already
// checked into the source code. We use --version because the output
// tends to be minimal and fewer operations are done to generate
// these so that the startup cost is still dominated by a more
// indispensible part of the CLI.
// NOTE: not all tools are present in tarball hence need to filter
const availableCli = [
'tools/eslint/node_modules/eslint/bin/eslint.js',
'deps/npm/bin/npx-cli.js',
'deps/npm/bin/npm-cli.js',
'deps/corepack/dist/corepack.js',
].filter((cli) => existsSync(path.resolve(__dirname, '../../', cli)));
const bench = common.createBenchmark(main, {
cli: availableCli,
n: [30],
});
function spawnProcess(cli, bench, state) {
const cmd = process.execPath || process.argv[0];
while (state.finished < state.n) {
const child = spawnSync(cmd, [cli, '--version'], {
env: { npm_config_loglevel: 'silent', ...process.env },
});
// Log some information for debugging if it fails, which it shouldn't.
if (child.status !== 0) {
console.log('---- STDOUT ----');
console.log(child.stdout.toString());
console.log('---- STDERR ----');
console.log(child.stderr.toString());
throw new Error(`Child process stopped with exit code ${child.status}`);
}
state.finished++;
if (state.finished === 0) {
// Finished warmup.
bench.start();
}
if (state.finished === state.n) {
bench.end(state.n);
}
}
}
function main({ n, cli }) {
cli = path.resolve(__dirname, '../../', cli);
const warmup = 3;
const state = { n, finished: -warmup };
spawnProcess(cli, bench, state);
}

View File

@ -0,0 +1,70 @@
'use strict';
const common = require('../common.js');
const { spawnSync } = require('child_process');
const path = require('path');
let Worker; // Lazy loaded in main
const bench = common.createBenchmark(main, {
script: [
'benchmark/fixtures/require-builtins',
'test/fixtures/semicolon',
'test/fixtures/snapshot/typescript',
],
mode: ['process', 'worker'],
n: [30],
});
function spawnProcess(script, bench, state) {
const cmd = process.execPath || process.argv[0];
while (state.finished < state.n) {
const child = spawnSync(cmd, [script]);
if (child.status !== 0) {
console.log('---- STDOUT ----');
console.log(child.stdout.toString());
console.log('---- STDERR ----');
console.log(child.stderr.toString());
throw new Error(`Child process stopped with exit code ${child.status}`);
}
state.finished++;
if (state.finished === 0) {
// Finished warmup.
bench.start();
}
if (state.finished === state.n) {
bench.end(state.n);
}
}
}
function spawnWorker(script, bench, state) {
const child = new Worker(script);
child.on('exit', (code) => {
if (code !== 0) {
throw new Error(`Worker stopped with exit code ${code}`);
}
state.finished++;
if (state.finished === 0) {
// Finished warmup.
bench.start();
}
if (state.finished < state.n) {
spawnWorker(script, bench, state);
} else {
bench.end(state.n);
}
});
}
function main({ n, script, mode }) {
script = path.resolve(__dirname, '../../', `${script}.js`);
const warmup = 3;
const state = { n, finished: -warmup };
if (mode === 'worker') {
Worker = require('worker_threads').Worker;
spawnWorker(script, bench, state);
} else {
spawnProcess(script, bench, state);
}
}

View File

@ -0,0 +1,46 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: ['string', 'object', 'arraybuffer'],
n: [1e4],
});
function main({ n, type }) {
const data = [];
switch (type) {
case 'string':
for (let i = 0; i < n; ++i) {
data.push(new Date().toISOString());
}
break;
case 'object':
for (let i = 0; i < n; ++i) {
data.push({ ...process.config });
}
break;
case 'arraybuffer':
for (let i = 0; i < n; ++i) {
data.push(new ArrayBuffer(10));
}
break;
default:
throw new Error('Unsupported payload type');
}
const run = type === 'arraybuffer' ? (i) => {
data[i] = structuredClone(data[i], { transfer: [ data[i] ] });
} : (i) => {
data[i] = structuredClone(data[i]);
};
bench.start();
for (let i = 0; i < n; ++i) {
run(i);
}
bench.end(n);
assert.strictEqual(data.length, n);
}

53
benchmark/misc/trace.js Normal file
View File

@ -0,0 +1,53 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [100000],
method: ['trace', 'isTraceCategoryEnabled'],
}, {
flags: [
'--expose-internals',
'--no-warnings',
'--trace-event-categories', 'foo',
],
});
const {
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent,
} = common.binding('constants').trace;
function doTrace(n, trace) {
bench.start();
for (let i = 0; i < n; i++) {
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
}
bench.end(n);
}
function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
bench.start();
for (let i = 0; i < n; i++) {
isTraceCategoryEnabled('foo');
isTraceCategoryEnabled('bar');
}
bench.end(n);
}
function main({ n, method }) {
const {
trace,
isTraceCategoryEnabled,
} = common.binding('trace_events');
switch (method) {
case 'trace':
doTrace(n, trace);
break;
case 'isTraceCategoryEnabled':
doIsTraceCategoryEnabled(n, isTraceCategoryEnabled);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}

View File

@ -0,0 +1,30 @@
'use strict';
const common = require('../common.js');
const util = require('util');
const bench = common.createBenchmark(main, {
type: ['extend', 'assign'],
n: [10e4],
});
function main({ n, type }) {
let fn;
if (type === 'extend') {
fn = util._extend;
} else if (type === 'assign') {
fn = Object.assign;
}
// Force-optimize the method to test so that the benchmark doesn't
// get disrupted by the optimizer kicking in halfway through.
for (let i = 0; i < type.length * 10; i += 1)
fn({}, process.env);
const obj = new Proxy({}, { set: function(a, b, c) { return true; } });
bench.start();
for (let j = 0; j < n; j += 1)
fn(obj, process.env);
bench.end(n);
}