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,58 @@
'use strict';
const common = require('../common');
const bench = common.createBenchmark(main, {
n: [1e6],
v: [
'() => 1n',
'() => true',
'() => false',
'() => 2',
'() => +0',
'() => -0',
'() => NaN',
'() => Infinity',
'() => ""',
'() => "\'"',
'() => Symbol("foo")',
'() => function foo() {}',
'() => null',
'() => undefined',
'() => new Array()',
'() => new BigInt64Array()',
'() => new BigUint64Array()',
'() => new Int8Array()',
'() => new Int16Array()',
'() => new Int32Array()',
'() => new Float32Array()',
'() => new Float64Array()',
'() => new Uint8Array()',
'() => new Uint8ClampedArray()',
'() => new Uint16Array()',
'() => new Uint32Array()',
'() => new Date()',
'() => new Map()',
'() => new WeakMap()',
'() => new Object()',
'() => Promise.resolve("foo")',
'() => new Set()',
'() => new WeakSet()',
'() => ({ __proto__: null })',
],
}, {
flags: ['--expose-internals'],
});
function main({ n, v }) {
const {
determineSpecificType,
} = require('internal/errors');
const value = eval(v)();
bench.start();
for (let i = 0; i < n; ++i)
determineSpecificType(value);
bench.end(n);
}

View File

@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1e5],
}, {
flags: ['--expose-internals'],
});
const instances = Array.from({ length: 1000 }).map(() => 'Uint8Array');
function main({ n }) {
const {
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
bench.start();
for (let i = 0; i < n; ++i)
new ERR_INVALID_ARG_TYPE('target', instances, 'test');
bench.end(n);
}

14
benchmark/error/error.js Normal file
View File

@ -0,0 +1,14 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1e7],
});
function main({ n }) {
bench.start();
for (let i = 0; i < n; ++i)
new Error('test');
bench.end(n);
}

View File

@ -0,0 +1,44 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1e7],
input: [
'',
'a',
'a,b',
'a,b,c',
'a,b,c,d',
],
type: [
'undefined',
'and',
'or',
],
}, {
flags: ['--expose-internals'],
});
function main({ n, input, type }) {
const {
formatList,
} = require('internal/errors');
const list = input.split(',');
if (type === 'undefined') {
bench.start();
for (let i = 0; i < n; ++i) {
formatList(list);
}
bench.end(n);
return;
}
bench.start();
for (let i = 0; i < n; ++i) {
formatList(list, type);
}
bench.end(n);
}

View File

@ -0,0 +1,62 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: [
'hide-stackframes',
'direct-call',
],
n: [1e7],
}, {
flags: ['--expose-internals'],
});
function main({ n, type }) {
const {
hideStackFrames,
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
const testfn = (value) => {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value);
}
};
const hideStackFramesTestfn = hideStackFrames((value) => {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE.HideStackFrameError('Benchmark', 'number', value);
}
});
const fn = type === 'hide-stackframe' ? hideStackFramesTestfn : testfn;
const value = 42;
const length = 1024;
const array = [];
const errCase = false;
for (let i = 0; i < length; ++i) {
array.push(fn(value));
}
bench.start();
for (let i = 0; i < n; i++) {
const index = i % length;
array[index] = fn(value);
}
bench.end(n);
// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], errCase ? 'object' : 'undefined');
}
}

View File

@ -0,0 +1,87 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: [
'hide-stackframes',
'direct-call',
],
double: ['true', 'false'],
n: [1e5],
}, {
flags: ['--expose-internals'],
});
function main({ n, type, double }) {
const {
hideStackFrames,
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
const value = 'err';
const testfn = (value) => {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value);
}
};
const hideStackFramesTestfn = hideStackFrames((value) => {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE.HideStackFrameError('Benchmark', 'number', value);
}
});
function doubleTestfn(value) {
testfn(value);
}
const doubleHideStackFramesTestfn = hideStackFrames((value) => {
hideStackFramesTestfn.withoutStackTrace(value);
});
const fn = type === 'hide-stackframe' ?
double === 'true' ?
doubleHideStackFramesTestfn :
hideStackFramesTestfn :
double === 'true' ?
doubleTestfn :
testfn;
const length = 1024;
const array = [];
let errCase = false;
// Warm up.
for (let i = 0; i < length; ++i) {
try {
fn(value);
} catch (e) {
errCase = true;
array.push(e);
}
}
bench.start();
for (let i = 0; i < n; i++) {
const index = i % length;
try {
fn(value);
} catch (e) {
array[index] = e;
}
}
bench.end(n);
// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], errCase ? 'object' : 'undefined');
}
}

View File

@ -0,0 +1,66 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1e6],
code: [
'built-in',
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
'ERR_INVALID_STATE',
'ERR_INVALID_URL',
],
stackTraceLimit: [0, 10],
}, {
flags: ['--expose-internals'],
});
function getErrorFactory(code) {
const {
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
ERR_INVALID_STATE,
ERR_INVALID_URL,
} = require('internal/errors').codes;
switch (code) {
case 'built-in':
return (n) => new Error();
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY();
case 'ERR_INVALID_STATE':
return (n) => new ERR_INVALID_STATE(n + '');
case 'ERR_INVALID_URL':
return (n) => new ERR_INVALID_URL({ input: n + '' });
default:
throw new Error(`${code} not supported`);
}
}
function main({ n, code, stackTraceLimit }) {
const getError = getErrorFactory(code);
Error.stackTraceLimit = stackTraceLimit;
// Warm up.
const length = 1024;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(getError(i));
}
bench.start();
for (let i = 0; i < n; ++i) {
const index = i % length;
array[index] = getError(index);
}
bench.end(n);
// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], 'object');
}
}

View File

@ -0,0 +1,62 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1e6],
code: [
'built-in',
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
'ERR_INVALID_STATE',
],
stackTraceLimit: [0, 10],
}, {
flags: ['--expose-internals'],
});
function getErrorStackFactory(code) {
const {
ERR_INVALID_STATE,
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
} = require('internal/errors').codes;
switch (code) {
case 'built-in':
return (n) => new Error().stack;
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY().stack;
case 'ERR_INVALID_STATE':
return (n) => new ERR_INVALID_STATE(n + '').stack;
default:
throw new Error(`${code} not supported`);
}
}
function main({ n, code, stackTraceLimit }) {
const getStack = getErrorStackFactory(code);
Error.stackTraceLimit = stackTraceLimit;
// Warm up.
const length = 1024;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(getStack(i));
}
bench.start();
for (let i = 0; i < n; ++i) {
const index = i % length;
array[index] = getStack(index);
}
bench.end(n);
// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], 'string');
}
}

View File

@ -0,0 +1,64 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1e6],
code: [
'built-in',
'ERR_FS_CP_DIR_TO_NON_DIR',
],
stackTraceLimit: [0, 10],
}, {
flags: ['--expose-internals'],
});
function getErrorFactory(code) {
const {
ERR_FS_CP_DIR_TO_NON_DIR,
} = require('internal/errors').codes;
switch (code) {
case 'built-in':
return (n) => new Error();
case 'ERR_FS_CP_DIR_TO_NON_DIR':
return (n) => new ERR_FS_CP_DIR_TO_NON_DIR({
message: 'cannot overwrite directory',
path: 'dest',
syscall: 'cp',
errno: 21,
code: 'EISDIR',
});
default:
throw new Error(`${code} not supported`);
}
}
function main({ n, code, stackTraceLimit }) {
const getError = getErrorFactory(code);
Error.stackTraceLimit = stackTraceLimit;
// Warm up.
const length = 1024;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(getError(i));
}
bench.start();
for (let i = 0; i < n; ++i) {
const index = i % length;
array[index] = getError(index);
}
bench.end(n);
// Verify the entries to prevent dead code elimination from making
// the benchmark invalid.
for (let i = 0; i < length; ++i) {
assert.strictEqual(typeof array[i], 'object');
}
}