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,37 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [200],
size: [2, 75],
});
const baseObject = {
a: 1,
b: {
c: 2,
d: [3, 4, 5],
e: 'fghi',
j: {
k: 6,
},
},
};
function createObjects(size) {
return Array.from({ length: size }, () => baseObject);
}
function main({ n, size }) {
bench.start();
for (let i = 0; i < n; ++i) {
new assert.AssertionError({
actual: {},
expected: createObjects(size),
operator: 'partialDeepStrictEqual',
stackStartFunction: () => {},
});
}
bench.end(n);
}

View File

@ -0,0 +1,53 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e4],
len: [1e2, 1e3],
strict: [0, 1],
arrayBuffer: [0, 1],
method: ['deepEqual', 'notDeepEqual', 'unequal_length', 'partial'],
}, {
combinationFilter: (p) => {
return p.strict === 1 || p.method === 'deepEqual';
},
});
function main({ len, n, method, strict, arrayBuffer }) {
let actual = Buffer.alloc(len);
let expected = Buffer.alloc(len + Number(method === 'unequal_length'));
if (method === 'unequal_length') {
method = 'notDeepEqual';
}
if (method === 'partial') {
method = 'partialDeepStrictEqual';
} else if (strict) {
method = method.replace('eep', 'eepStrict');
}
for (let i = 0; i < len; i++) {
actual.writeInt8(i % 128, i);
expected.writeInt8(i % 128, i);
}
if (method.includes('not')) {
const position = Math.floor(len / 2);
expected[position] = expected[position] + 1;
}
const fn = assert[method];
if (arrayBuffer) {
actual = actual.buffer;
expected = expected.buffer;
}
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,80 @@
'use strict';
const common = require('../common.js');
const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } =
require('assert');
const bench = common.createBenchmark(main, {
n: [2e3],
len: [5e2],
strict: [0, 1],
method: [
'deepEqual_primitiveOnly',
'deepEqual_objectOnly',
'deepEqual_mixed',
'notDeepEqual_primitiveOnly',
'notDeepEqual_objectOnly',
'notDeepEqual_mixed',
],
});
function benchmark(method, n, values, values2) {
const actual = new Map(values);
// Prevent reference equal elements
const deepCopy = JSON.parse(JSON.stringify(values2 ? values2 : values));
const expected = new Map(deepCopy);
bench.start();
for (let i = 0; i < n; ++i) {
method(actual, expected);
}
bench.end(n);
}
function main({ n, len, method, strict }) {
const array = Array.from({ length: len }, () => '');
switch (method) {
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => [`str_${i}`, 123]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
}
case 'deepEqual_objectOnly': {
const values = array.map((_, i) => [[`str_${i}`, 1], 123]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
}
case 'deepEqual_mixed': {
const values = array.map(
(_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123],
);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
}
case 'notDeepEqual_primitiveOnly': {
const values = array.map((_, i) => [`str_${i}`, 123]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t', 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
}
case 'notDeepEqual_objectOnly': {
const values = array.map((_, i) => [[`str_${i}`, 1], 123]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = [['w00t'], 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
}
case 'notDeepEqual_mixed': {
const values = array.map(
(_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123],
);
const values2 = values.slice(0);
values2[0] = ['w00t', 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
}
default:
throw new Error(`Unsupported method ${method}`);
}
}

View File

@ -0,0 +1,43 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [50, 2e2],
size: [1e2, 1e4],
method: ['deepEqual', 'notDeepEqual', 'deepStrictEqual', 'notDeepStrictEqual'],
}, {
combinationFilter: (p) => {
return p.size === 1e4 && p.n === 50 ||
p.size === 1e3 && p.n === 2e2 ||
p.size === 1e2 && p.n === 2e3 ||
p.size === 1;
},
});
function createObj(size, add = '') {
return Array.from({ length: size }, (n) => ({
foo: 'yarp',
nope: {
bar: `123${add}`,
a: [1, 2, 3],
baz: n,
c: {},
b: [],
},
}));
}
function main({ size, n, method }) {
const fn = assert[method];
const actual = createObj(size);
const expected = method.includes('not') ? createObj(size, '4') : createObj(size);
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,80 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const circular = {};
circular.circular = circular;
const circular2 = {};
circular2.circular = circular2;
const notCircular = {};
notCircular.circular = {};
const primValues = {
'null_prototype': { __proto__: null },
'string': 'abcdef',
'number': 1_000,
'boolean': true,
'object': { property: 'abcdef' },
'array': [1, 2, 3],
'set_object': new Set([[1]]),
'set_simple': new Set([1, 2, 3]),
'circular': circular,
'empty_object': {},
'regexp': /abc/i,
'date': new Date(),
};
const primValues2 = {
'null_prototype': { __proto__: null },
'object': { property: 'abcdef' },
'array': [1, 2, 3],
'set_object': new Set([[1]]),
'set_simple': new Set([1, 3, 2]),
'circular': circular2,
'empty_object': {},
'regexp': /abc/i,
'date': new Date(primValues.date),
};
const primValuesUnequal = {
'null_prototype': { __proto__: { __proto__: null } },
'string': 'abcdez',
'number': 1_001,
'boolean': false,
'object': { property2: 'abcdef' },
'array': [1, 3, 2],
'set_object': new Set([[2]]),
'set_simple': new Set([1, 4, 2]),
'circular': notCircular,
'empty_object': [],
'regexp': /abc/g,
'date': new Date(primValues.date.getTime() + 1),
};
const bench = common.createBenchmark(main, {
primitive: Object.keys(primValues),
n: [1e5],
strict: [0, 1],
method: ['deepEqual', 'notDeepEqual'],
}, {
combinationFilter: (p) => {
return p.strict === 1 || p.method === 'deepEqual';
},
});
function main({ n, primitive, method, strict }) {
const prim = primValues[primitive];
const actual = primValues2[primitive] ?? prim;
const expected = method.includes('not') ? primValuesUnequal[primitive] : prim;
if (strict) {
method = method.replace('eep', 'eepStrict');
}
const fn = assert[method];
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,99 @@
'use strict';
const common = require('../common.js');
const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } =
require('assert');
const bench = common.createBenchmark(main, {
n: [1e3],
len: [2, 1e2],
strict: [0, 1],
order: ['insert', 'random', 'reversed'],
method: [
'deepEqual_primitiveOnly',
'deepEqual_objectOnly',
'deepEqual_mixed',
'notDeepEqual_primitiveOnly',
'notDeepEqual_objectOnly',
'notDeepEqual_mixed',
],
}, {
combinationFilter(p) {
return p.order !== 'random' || p.strict === 1 && p.method !== 'notDeepEqual_objectOnly';
},
});
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
function benchmark(method, n, values, values2, order) {
const actual = new Set(values);
// Prevent reference equal elements
let deepCopy = JSON.parse(JSON.stringify(values2));
if (order === 'reversed') {
deepCopy = deepCopy.reverse();
} else if (order === 'random') {
shuffleArray(deepCopy);
}
const expected = new Set(deepCopy);
bench.start();
for (let i = 0; i < n; ++i) {
method(actual, expected);
}
bench.end(n);
}
function main({ n, len, method, strict, order }) {
const array = Array.from({ length: len }, () => '');
switch (method) {
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => `str_${i}`);
benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order);
break;
}
case 'deepEqual_objectOnly': {
const values = array.map((_, i) => [`str_${i}`, null]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order);
break;
}
case 'deepEqual_mixed': {
const values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order);
break;
}
case 'notDeepEqual_primitiveOnly': {
const values = array.map((_, i) => `str_${i}`);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = 'w00t';
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order);
break;
}
case 'notDeepEqual_objectOnly': {
const values = array.map((_, i) => [`str_${i}`, null]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t'];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order);
break;
}
case 'notDeepEqual_mixed': {
const values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
const values2 = values.slice();
values2[0] = 'w00t';
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order);
break;
}
default:
throw new Error(`Unsupported method "${method}"`);
}
}

View File

@ -0,0 +1,71 @@
'use strict';
const common = require('../common.js');
const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } =
require('assert');
const bench = common.createBenchmark(main, {
n: [1e3],
len: [1e4],
strict: [1],
method: [
'deepEqual_Array',
'notDeepEqual_Array',
'deepEqual_sparseArray',
'notDeepEqual_sparseArray',
'deepEqual_Set',
'notDeepEqual_Set',
],
});
function run(fn, n, actual, expected) {
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}
function main({ n, len, method, strict }) {
let actual = Array.from({ length: len }, (_, i) => i);
// Contain one undefined value to trigger a specific code path
actual[0] = undefined;
let expected = actual.slice(0);
if (method.includes('not')) {
expected[len - 1] += 1;
}
switch (method) {
case 'deepEqual_sparseArray':
case 'notDeepEqual_sparseArray':
actual = new Array(len);
for (let i = 0; i < len; i += 2) {
actual[i] = i;
}
expected = actual.slice(0);
if (method.includes('not')) {
expected[len - 2] += 1;
run(strict ? notDeepStrictEqual : notDeepEqual, n, actual, expected);
} else {
run(strict ? deepStrictEqual : deepEqual, n, actual, expected);
}
break;
case 'deepEqual_Array':
run(strict ? deepStrictEqual : deepEqual, n, actual, expected);
break;
case 'notDeepEqual_Array':
run(strict ? notDeepStrictEqual : notDeepEqual, n, actual, expected);
break;
case 'deepEqual_Set':
run(strict ? deepStrictEqual : deepEqual,
n, new Set(actual), new Set(expected));
break;
case 'notDeepEqual_Set':
run(strict ? notDeepStrictEqual : notDeepEqual,
n, new Set(actual), new Set(expected));
break;
default:
throw new Error(`Unsupported method "${method}"`);
}
}

View File

@ -0,0 +1,51 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: [
'Int8Array',
'Uint8Array',
'Float32Array',
'Uint32Array',
],
n: [25000],
strict: [0, 1],
method: [
'deepEqual',
'notDeepEqual',
],
len: [1e2, 5e3],
}, {
combinationFilter(p) {
return p.strict === 1 ||
p.type !== 'Float32Array' ||
p.len === 1e2;
},
});
function main({ type, n, len, method, strict }) {
const clazz = global[type];
const actual = new clazz(len);
const expected = new clazz(len);
if (strict) {
method = method.replace('eep', 'eepStrict');
}
const fn = assert[method];
if (method.includes('not')) {
expected[Math.floor(len / 2)] = 123;
}
bench.start();
for (let i = 0; i < n; ++i) {
actual[0] = i;
expected[0] = i;
const pos = Math.ceil(len / 2) + 1;
actual[pos] = i;
expected[pos] = i;
fn(actual, expected);
}
bench.end(n);
}

28
benchmark/assert/match.js Normal file
View File

@ -0,0 +1,28 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e7],
method: ['match', 'doesNotMatch'],
}, {
combinationFilter(p) {
// These benchmarks purposefully do not run by default. They do not provide
// might insight, due to only being a small wrapper around a native regexp
// call.
return p.n === 1;
},
});
function main({ n, method }) {
const fn = assert[method];
const actual = 'Example of string that will match';
const expected = method === 'match' ? /will match/ : /will not match/;
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,170 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [125],
size: [500],
extraProps: [0, 1],
datasetName: [
'objects',
'sets',
'setsWithObjects',
'maps',
'circularRefs',
'typedArrays',
'arrayBuffers',
'dataViewArrayBuffers',
'array',
],
});
function createArray(length, extraProps) {
if (extraProps) {
return Array.from({ length: length * 4 }, (_, i) => i);
}
return Array.from({ length }, (_, i) => i * 4);
}
function createObjects(length, extraProps, depth = 0) {
return Array.from({ length }, (_, i) => ({
foo: 'yarp',
nope: {
bar: '123',
...(extraProps ? { a: [1, 2, i] } : {}),
c: {},
b: !depth ? createObjects(2, extraProps, depth + 1) : [],
},
}));
}
function createSetsWithObjects(length, extraProps, depth = 0) {
return Array.from({ length }, (_, i) => new Set([
...(extraProps ? [{}] : []),
{
simple: 'object',
number: i,
},
['array', 'with', 'values'],
new Set([[], {}, { nested: i }]),
]));
}
function createSets(length, extraProps, depth = 0) {
return Array.from({ length }, (_, i) => new Set([
'yarp',
...(extraProps ? ['123', 1, 2] : []),
i + 3,
null,
{
simple: 'object',
number: i,
},
['array', 'with', 'values'],
!depth ? new Set([1, { nested: i }]) : new Set(),
!depth ? createSets(2, extraProps, depth + 1) : null,
]));
}
function createMaps(length, extraProps, depth = 0) {
return Array.from({ length }, (_, i) => new Map([
...(extraProps ? [['primitiveKey', 'primitiveValue']] : []),
[42, 'numberKey'],
['objectValue', { a: 1, b: i }],
['arrayValue', [1, 2, i]],
['nestedMap', new Map([['a', i], ['b', { deep: true }]])],
[{ objectKey: true }, 'value from object key'],
[[1, i, 3], 'value from array key'],
[!depth ? createMaps(2, extraProps, depth + 1) : null, 'recursive value' + i],
]));
}
function createCircularRefs(length, extraProps) {
return Array.from({ length }, (_, i) => {
const circularSet = new Set();
const circularMap = new Map();
const circularObj = { name: 'circular object' };
circularSet.add('some value' + i);
circularSet.add(circularSet);
circularMap.set('self', circularMap);
circularMap.set('value', 'regular value');
circularObj.self = circularObj;
const objA = { name: 'A' };
const objB = { name: 'B' };
objA.ref = objB;
objB.ref = objA;
circularSet.add(objA);
circularMap.set('objB', objB);
return {
circularSet,
circularMap,
...extraProps ? { extra: i } : {},
circularObj,
objA,
objB,
};
});
}
function createTypedArrays(length, extraParts) {
const extra = extraParts ? [9, 8, 7] : [];
return Array.from({ length }, (_, i) => {
return {
uint8: new Uint8Array(new ArrayBuffer(32), 4, 4),
int16: new Int16Array([1, 2, ...extra, 3]),
uint32: new Uint32Array([i + 1, i + 2, ...extra, i + 3]),
float64: new Float64Array([1.1, 2.2, ...extra, i + 3.3]),
bigUint64: new BigUint64Array([1n, 2n, 3n]),
};
});
}
function createArrayBuffers(length, extra) {
return Array.from({ length }, (_, n) => {
const buffer = Buffer.alloc(n + (extra ? 1 : 0));
for (let i = 0; i < n; i++) {
buffer.writeInt8(i % 128, i);
}
return buffer.buffer;
});
}
function createDataViewArrayBuffers(length, extra) {
return createArrayBuffers(length, extra).map((buffer) => new DataView(buffer));
}
const datasetMappings = {
objects: createObjects,
sets: createSets,
setsWithObjects: createSetsWithObjects,
maps: createMaps,
circularRefs: createCircularRefs,
typedArrays: createTypedArrays,
arrayBuffers: createArrayBuffers,
dataViewArrayBuffers: createDataViewArrayBuffers,
array: createArray,
};
function getDatasets(datasetName, size, extra) {
return {
actual: datasetMappings[datasetName](size, true),
expected: datasetMappings[datasetName](size, !extra),
};
}
function main({ size, n, datasetName, extraProps }) {
const { actual, expected } = getDatasets(datasetName, size, extraProps);
bench.start();
for (let i = 0; i < n; ++i) {
assert.partialDeepStrictEqual(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,34 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e5],
method: ['rejects', 'doesNotReject'],
}, {
combinationFilter(p) {
// These benchmarks purposefully do not run by default. They do not provide
// much insight, due to only being a small wrapper around a native promise
// with a few extra checks.
return p.n === 1;
},
});
async function main({ n, method }) {
const fn = assert[method];
const shouldReject = method === 'rejects';
bench.start();
for (let i = 0; i < n; ++i) {
await fn(async () => {
const err = new Error(`assert.${method}`);
if (shouldReject) {
throw err;
} else {
return err;
}
});
}
bench.end(n);
}

View File

@ -0,0 +1,49 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e5],
type: ['string', 'object', 'number'],
method: ['strictEqual', 'notStrictEqual'],
}, {
combinationFilter(p) {
// These benchmarks purposefully do not run by default. They do not provide
// much insight, due to only being a small wrapper around `Object.is()`.
return p.n === 1;
},
});
function main({ type, n, method }) {
const fn = assert[method];
let actual, expected;
switch (type) {
case 'string':
actual = expected = 'Hello World';
if (method === 'notStrictEqual') {
expected += 'bar';
}
break;
case 'object':
actual = expected = { a: 'Hello', b: 'World' };
if (method === 'notStrictEqual') {
expected = { a: 'Hello', b: 'World' };
}
break;
case 'number':
actual = expected = 1e9;
if (method === 'notStrictEqual') {
expected += 1;
}
break;
default:
throw new Error('Unexpected type');
}
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

View File

@ -0,0 +1,33 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e5],
method: ['throws', 'doesNotThrow'],
}, {
combinationFilter(p) {
// These benchmarks purposefully do not run by default. They do not provide
// much insight, due to only being a small wrapper around a try / catch.
return p.n === 1;
},
});
function main({ n, method }) {
const fn = assert[method];
const shouldThrow = method === 'throws';
bench.start();
for (let i = 0; i < n; ++i) {
fn(() => {
const err = new Error(`assert.${method}`);
if (shouldThrow) {
throw err;
} else {
return err;
}
});
}
bench.end(n);
}