-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from RebeccaStevens/benchmark
- Loading branch information
Showing
8 changed files
with
328 additions
and
0 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
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,34 @@ | ||
{ | ||
"plugins": ["ava"], | ||
"extends": ["plugin:ava/recommended"], | ||
"rules": { | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"functional/immutable-data": "off", | ||
"functional/no-class": "off", | ||
"functional/no-conditional-statement": "off", | ||
"functional/no-expression-statement": "off", | ||
"functional/no-let": "off", | ||
"functional/no-loop-statement": "off", | ||
"functional/no-method-signature": "off", | ||
"functional/no-mixed-type": "off", | ||
"functional/no-return-void": "off", | ||
"functional/no-this-expression": "off", | ||
"functional/no-throw-statement": "off", | ||
"functional/no-try-statement": "off", | ||
"functional/prefer-readonly-type": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"import/no-relative-parent-imports": "off", | ||
"import/order": "off", | ||
"jsdoc/require-jsdoc": "off", | ||
"node/no-extraneous-import": "off", | ||
"sonarjs/no-duplicate-string": "off", | ||
"sonarjs/no-ignored-return": "off", | ||
"init-declarations": "off", | ||
"no-plusplus": "off" | ||
} | ||
} |
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,28 @@ | ||
{ | ||
"name": "deepmerge-ts-benchmark", | ||
"private": "true", | ||
"version": "0.0.0-development", | ||
"description": "Benchmark different deepmerge implementations", | ||
"author": { | ||
"name": "Rebecca Stevens", | ||
"email": "rebecca.stevens@outlook.co.nz" | ||
}, | ||
"scripts": { | ||
"prebenchmark": "yarn install; yarn link deepmerge-ts", | ||
"benchmark": "ts-node run.ts" | ||
}, | ||
"dependencies": { | ||
"@types/benchmark": "^2.1.1", | ||
"benchmark": "^2.1.4", | ||
"deepmerge": "^4.2.2", | ||
"lodash": "^4.17.21", | ||
"merge-anything": "^4.0.1", | ||
"object-accumulator": "^0.0.5" | ||
}, | ||
"engines": { | ||
"node": ">=12.4.0" | ||
}, | ||
"devDependencies": { | ||
"ts-node": "^10.2.1" | ||
} | ||
} |
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,93 @@ | ||
import Benchmark from "benchmark"; | ||
|
||
import { deepmerge as deepmergeTs } from "deepmerge-ts"; | ||
import { all as deepmerge } from "deepmerge"; | ||
import { merge as mergeAnything } from "merge-anything"; | ||
import { Accumulator as ObjectAccumulator } from "object-accumulator"; | ||
import { merge as lodashMerge } from "lodash"; | ||
|
||
console.log("Generating benchmark data."); | ||
|
||
const benchmarkData = generateBenchmarkDataArray(100, 10, 4); | ||
|
||
console.log("Running benchmarks."); | ||
|
||
const suite = new Benchmark.Suite(); | ||
|
||
// add tests | ||
suite | ||
.add("deepmerge-ts", () => { | ||
deepmergeTs(...benchmarkData); | ||
}) | ||
.add("deepmerge", () => { | ||
deepmerge(benchmarkData); | ||
}) | ||
.add("merge-anything", () => { | ||
(mergeAnything as any)(...benchmarkData); | ||
}) | ||
.add("object-accumulator", () => { | ||
ObjectAccumulator.from(benchmarkData).merge(); | ||
}) | ||
.add("lowdash merge", () => { | ||
lodashMerge({}, benchmarkData); | ||
}) | ||
.on("cycle", (event: any) => { | ||
console.log(String(event.target)); | ||
}) | ||
// eslint-disable-next-line func-names | ||
.on("complete", function () { | ||
// @ts-expect-error When need to access the "this" value | ||
// eslint-disable-next-line unicorn/no-this-assignment, @typescript-eslint/no-this-alias, no-invalid-this | ||
const results = this; | ||
|
||
console.log(`\nFastest is ${results.filter("fastest").map("name")}`); | ||
}) | ||
.run({ async: true }); | ||
|
||
function generateBenchmarkDataArray(items, maxProperties, maxDepth) { | ||
const data: object[] = []; | ||
|
||
for (let i = 0; i < items; i++) { | ||
data.push(generateBenchmarkDataItem(maxProperties, maxDepth)); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
function generateBenchmarkDataItem(maxProperties, depth, currentDepth = 0) { | ||
const obj = {}; | ||
|
||
const properties = Math.floor(maxProperties * Math.random()) + 1; | ||
|
||
const propertiesOptions = shuffle( | ||
Array.from({ length: maxProperties }, (_, i) => String.fromCharCode(i + 65)) | ||
); | ||
|
||
for (let i = 0; i < properties; i++) { | ||
const prop = propertiesOptions[i]; | ||
|
||
obj[prop] = | ||
currentDepth < depth | ||
? generateBenchmarkDataItem(maxProperties, depth, currentDepth + 1) | ||
: "value"; | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
function shuffle(array) { | ||
let currentIndex = array.length; | ||
let randomIndex; | ||
|
||
while (currentIndex !== 0) { | ||
randomIndex = Math.floor(Math.random() * currentIndex); | ||
currentIndex--; | ||
|
||
[array[currentIndex], array[randomIndex]] = [ | ||
array[randomIndex], | ||
array[currentIndex], | ||
]; | ||
} | ||
|
||
return array; | ||
} |
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,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"esModuleInterop": true, | ||
"exactOptionalPropertyTypes": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"importHelpers": false, | ||
"lib": [ | ||
"ESNext", | ||
], | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"newLine": "LF", | ||
"noEmitOnError": true, | ||
"noImplicitReturns": true, | ||
"noImplicitAny": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"pretty": true, | ||
"resolveJsonModule": true, | ||
"sourceMap": false, | ||
"strict": true, | ||
"alwaysStrict": true, | ||
"target": "ES2018", | ||
}, | ||
} |
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,139 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@cspotcode/source-map-consumer@0.8.0": | ||
version "0.8.0" | ||
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" | ||
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== | ||
|
||
"@cspotcode/source-map-support@0.6.1": | ||
version "0.6.1" | ||
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.6.1.tgz#118511f316e2e87ee4294761868e254d3da47960" | ||
integrity sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg== | ||
dependencies: | ||
"@cspotcode/source-map-consumer" "0.8.0" | ||
|
||
"@tsconfig/node10@^1.0.7": | ||
version "1.0.8" | ||
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" | ||
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== | ||
|
||
"@tsconfig/node12@^1.0.7": | ||
version "1.0.9" | ||
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" | ||
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== | ||
|
||
"@tsconfig/node14@^1.0.0": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" | ||
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== | ||
|
||
"@tsconfig/node16@^1.0.2": | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" | ||
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== | ||
|
||
"@types/benchmark@^2.1.1": | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-2.1.1.tgz#d763df29717d93aa333eb11f421ef383a5df5673" | ||
integrity sha512-XmdNOarpSSxnb3DE2rRFOFsEyoqXLUL+7H8nSGS25vs+JS0018bd+cW5Ma9vdlkPmoTHSQ6e8EUFMFMxeE4l+g== | ||
|
||
acorn-walk@^8.1.1: | ||
version "8.2.0" | ||
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" | ||
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== | ||
|
||
acorn@^8.4.1: | ||
version "8.5.0" | ||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2" | ||
integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q== | ||
|
||
arg@^4.1.0: | ||
version "4.1.3" | ||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" | ||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== | ||
|
||
benchmark@^2.1.4: | ||
version "2.1.4" | ||
resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629" | ||
integrity sha1-CfPeMckWQl1JjMLuVloOvzwqVik= | ||
dependencies: | ||
lodash "^4.17.4" | ||
platform "^1.3.3" | ||
|
||
create-require@^1.1.0: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" | ||
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== | ||
|
||
deepmerge@^4.2.2: | ||
version "4.2.2" | ||
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" | ||
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== | ||
|
||
diff@^4.0.1: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" | ||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== | ||
|
||
is-what@^3.14.1: | ||
version "3.14.1" | ||
resolved "https://registry.yarnpkg.com/is-what/-/is-what-3.14.1.tgz#e1222f46ddda85dead0fd1c9df131760e77755c1" | ||
integrity sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA== | ||
|
||
lodash@^4.17.21, lodash@^4.17.4: | ||
version "4.17.21" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" | ||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== | ||
|
||
make-error@^1.1.1: | ||
version "1.3.6" | ||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" | ||
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== | ||
|
||
merge-anything@^4.0.1: | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/merge-anything/-/merge-anything-4.0.1.tgz#5c837cfa7adbb65fa5a4df178b37312493cb3609" | ||
integrity sha512-KsFjBYc3juDoHz9Vzd5fte1nqp06H8SQ+yU344Dd0ZunwSgtltnC0kgKds8cbocJGyViLcBQuHkitbDXAqW+LQ== | ||
dependencies: | ||
is-what "^3.14.1" | ||
ts-toolbelt "^9.3.12" | ||
|
||
object-accumulator@^0.0.5: | ||
version "0.0.5" | ||
resolved "https://registry.yarnpkg.com/object-accumulator/-/object-accumulator-0.0.5.tgz#fca5a536142f5e8a2f159f616b0ac9020371e39c" | ||
integrity sha512-UKkFOfHwuL+nHRSVRjTHv99h8gjeW/zHfgtfaaRM4WLbGvJbutlujegjN7YsL1EsJlB7Q1kGI12P93+yiY4snA== | ||
|
||
platform@^1.3.3: | ||
version "1.3.6" | ||
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" | ||
integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== | ||
|
||
ts-node@^10.2.1: | ||
version "10.2.1" | ||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.2.1.tgz#4cc93bea0a7aba2179497e65bb08ddfc198b3ab5" | ||
integrity sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw== | ||
dependencies: | ||
"@cspotcode/source-map-support" "0.6.1" | ||
"@tsconfig/node10" "^1.0.7" | ||
"@tsconfig/node12" "^1.0.7" | ||
"@tsconfig/node14" "^1.0.0" | ||
"@tsconfig/node16" "^1.0.2" | ||
acorn "^8.4.1" | ||
acorn-walk "^8.1.1" | ||
arg "^4.1.0" | ||
create-require "^1.1.0" | ||
diff "^4.0.1" | ||
make-error "^1.1.1" | ||
yn "3.1.1" | ||
|
||
ts-toolbelt@^9.3.12: | ||
version "9.6.0" | ||
resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz#50a25426cfed500d4a09bd1b3afb6f28879edfd5" | ||
integrity sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w== | ||
|
||
yn@3.1.1: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" | ||
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== |
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
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 |
---|---|---|
|
@@ -28,4 +28,7 @@ | |
"@/deepmerge": ["./index"], | ||
}, | ||
}, | ||
"exclude": [ | ||
"benchmark/" | ||
] | ||
} |