Skip to content

Commit

Permalink
feat: split benchmarks into simple and complex categories
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbae0 committed Dec 5, 2024
1 parent cffa675 commit f5a55c0
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 187 deletions.
38 changes: 38 additions & 0 deletions benchmark/complex/performance.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { complexObj1, complexObj2 } = require('../constant.cjs');

const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();

const { isEqual: underscoreIsEqual } = require('underscore');
const { isEqual: lodashIsEqual } = require('lodash');
const { isEqual: esToolkitisEqual } = require('es-toolkit');
const { dequal } = require('dequal');
const deepEqual = require('deep-equal');
const fastDeepEqual = require('fast-deep-equal');
const tinyIsEqual = require('../../dist/index.cjs').default;

suite.add('tiny-is-equal', () => {
return tinyIsEqual(complexObj1, complexObj2);
});
suite.add('dequal', () => {
return dequal(complexObj1, complexObj2);
});
suite.add('underscore.isEqual', () => {
return underscoreIsEqual(complexObj1, complexObj2);
});
suite.add('fast-deep-equal', () => {
return fastDeepEqual(complexObj1, complexObj2);
});
suite.add('es-toolkit.isEqual', () => {
return esToolkitisEqual(complexObj1, complexObj2);
});
suite.add('lodash.isEqual', () => {
return lodashIsEqual(complexObj1, complexObj2);
});
suite.add('deep-equal', () => {
return deepEqual(complexObj1, complexObj2);
});

suite
.on('cycle', event => console.log(String(event.target)))
.run({ async: true });
41 changes: 41 additions & 0 deletions benchmark/complex/performance.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { run, bench, summary } from 'mitata';
import { complexObj1, complexObj2 } from '../constant.cjs';

import { isEqual as underscoreIsEqual } from 'underscore';
import lodash from 'lodash';
const { isEqual: lodashIsEqual } = lodash;
import deepEql from 'deep-eql';
import deepEqual from 'deep-equal';
import { isEqual as esToolkitisEqual } from 'es-toolkit';
import { dequal } from 'dequal';
import fastDeepEqual from 'fast-deep-equal';
import tinyIsEqual from '../../dist/index.js';

summary(() => {
bench('underscore', () => {
return underscoreIsEqual(complexObj1, complexObj2);
});
bench('lodash', () => {
return lodashIsEqual(complexObj1, complexObj2);
});
bench('deep-eql', () => {
return deepEql(complexObj1, complexObj2);
});
bench('es-toolkit', () => {
return esToolkitisEqual(complexObj1, complexObj2);
});
bench('dequal', () => {
return dequal(complexObj1, complexObj2);
});
bench('deep-equal', () => {
return deepEqual(complexObj1, complexObj2);
});
bench('fast-deep-equal', () => {
return fastDeepEqual(complexObj1, complexObj2);
});
bench('tiny-is-equal', () => {
return tinyIsEqual(complexObj1, complexObj2);
});
});

await run();
101 changes: 101 additions & 0 deletions benchmark/constant.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const tinyIsEqual = require('../dist/index.cjs').default;

// Simple

const simpleMap = new Map();

Array.from({ length: 5 }, (_, i) => i).forEach(value =>
simpleMap.set(value.toString(), value),
);

const sampleSimpleObj = {
a: Number.NaN,
b: 100,
c: 'string',
d: [1, 2, 3, 4, 5, 6, 7, 8],
e: new Set([1, 2, 3, 4, 5]),
f: simpleMap,
g: /^(?=.*[A-Z])/g,
h: new Error('error'),
i: new Date('2000-01-01'),
j: new Uint8Array([1, 2, 3, 4, 5]).buffer,
k: new Uint8Array([1, 2, 3, 4, 5]),
l: new DataView(new Uint8Array([1, 2, 3, 4, 5]).buffer),
m: tinyIsEqual,
};
const sampleSimpleObj2 = {
a: Number.NaN,
b: 100,
c: 'string',
d: [1, 2, 3, 4, 5, 6, 7, 8],
e: new Set([1, 2, 3, 4, 5]),
f: simpleMap,
g: /^(?=.*[A-Z])/g,
h: new Error('error'),
i: new Date('2000-01-01'),
j: new Uint8Array([1, 2, 3, 4, 5]).buffer,
k: new Uint8Array([1, 2, 3, 4, 5]),
l: new DataView(new Uint8Array([1, 2, 3, 4, 5]).buffer),
m: tinyIsEqual,
};

const simpleObj1 = { ...sampleSimpleObj };
const simpleObj2 = { ...sampleSimpleObj2 };

// Complex

const longArray = Array.from({ length: 100 }, (_, i) => i);
const longRegex =
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,100}$/g;
const longString =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
const longMap = new Map();

longArray.forEach(value => longMap.set(value.toString(), value));

const sampleComplexObj = {
a: Number.NaN,
b: longString,
c: longArray,
d: new Set(longArray),
e: longMap,
f: longRegex,
g: new Error(longString),
h: new Date('2000-01-01'),
i: new Uint8Array(longArray).buffer,
j: new Uint8Array(longArray),
k: new DataView(new Uint8Array(longArray).buffer),
// l: new WeakSet(),
// m: new WeakMap(),
n: tinyIsEqual,
};
const sampleComplexObj2 = {
a: Number.NaN,
b: longString,
c: longArray,
d: new Set(longArray),
e: longMap,
f: longRegex,
g: new Error(longString),
h: new Date('2000-01-01'),
i: new Uint8Array(longArray).buffer,
j: new Uint8Array(longArray),
k: new DataView(new Uint8Array(longArray).buffer),
// l: new WeakSet(),
// m: new WeakMap(),
n: tinyIsEqual,
};

const complexObj1 = {
...sampleComplexObj,
nestedObj: { ...sampleComplexObj, deepNestedObj: { ...sampleComplexObj } },
};
const complexObj2 = {
...sampleComplexObj2,
nestedObj: {
...sampleComplexObj2,
deepNestedObj: { ...sampleComplexObj2 },
},
};

module.exports = { simpleObj1, simpleObj2, complexObj1, complexObj2 };
101 changes: 101 additions & 0 deletions benchmark/constant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import tinyIsEqual from '../dist/index.js';

// Simple

const simpleMap = new Map();

Array.from({ length: 5 }, (_, i) => i).forEach(value =>
simpleMap.set(value.toString(), value),
);

const sampleSimpleObj = {
a: Number.NaN,
b: 100,
c: 'string',
d: [1, 2, 3, 4, 5, 6, 7, 8],
e: new Set([1, 2, 3, 4, 5]),
f: simpleMap,
g: /^(?=.*[A-Z])/g,
h: new Error('error'),
i: new Date('2000-01-01'),
j: new Uint8Array([1, 2, 3, 4, 5]).buffer,
k: new Uint8Array([1, 2, 3, 4, 5]),
l: new DataView(new Uint8Array([1, 2, 3, 4, 5]).buffer),
m: tinyIsEqual,
};
const sampleSimpleObj2 = {
a: Number.NaN,
b: 100,
c: 'string',
d: [1, 2, 3, 4, 5, 6, 7, 8],
e: new Set([1, 2, 3, 4, 5]),
f: simpleMap,
g: /^(?=.*[A-Z])/g,
h: new Error('error'),
i: new Date('2000-01-01'),
j: new Uint8Array([1, 2, 3, 4, 5]).buffer,
k: new Uint8Array([1, 2, 3, 4, 5]),
l: new DataView(new Uint8Array([1, 2, 3, 4, 5]).buffer),
m: tinyIsEqual,
};

const simpleObj1 = { ...sampleSimpleObj };
const simpleObj2 = { ...sampleSimpleObj2 };

// Complex

const longArray = Array.from({ length: 100 }, (_, i) => i);
const longRegex =
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,100}$/g;
const longString =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
const longMap = new Map();

longArray.forEach(value => longMap.set(value.toString(), value));

const sampleComplexObj = {
a: Number.NaN,
b: longString,
c: longArray,
d: new Set(longArray),
e: longMap,
f: longRegex,
g: new Error(longString),
h: new Date('2000-01-01'),
i: new Uint8Array(longArray).buffer,
j: new Uint8Array(longArray),
k: new DataView(new Uint8Array(longArray).buffer),
// l: new WeakSet(),
// m: new WeakMap(),
n: tinyIsEqual,
};
const sampleComplexObj2 = {
a: Number.NaN,
b: longString,
c: longArray,
d: new Set(longArray),
e: longMap,
f: longRegex,
g: new Error(longString),
h: new Date('2000-01-01'),
i: new Uint8Array(longArray).buffer,
j: new Uint8Array(longArray),
k: new DataView(new Uint8Array(longArray).buffer),
// l: new WeakSet(),
// m: new WeakMap(),
n: tinyIsEqual,
};

const complexObj1 = {
...sampleComplexObj,
nestedObj: { ...sampleComplexObj, deepNestedObj: { ...sampleComplexObj } },
};
const complexObj2 = {
...sampleComplexObj2,
nestedObj: {
...sampleComplexObj2,
deepNestedObj: { ...sampleComplexObj2 },
},
};

export { simpleObj1, simpleObj2, complexObj1, complexObj2 };
80 changes: 0 additions & 80 deletions benchmark/performance.cjs

This file was deleted.

Loading

0 comments on commit f5a55c0

Please sign in to comment.