-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split benchmarks into simple and complex categories
- Loading branch information
Showing
9 changed files
with
364 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.