From b0ab8640be1eb0a420abb6335a5046f185eadf8f Mon Sep 17 00:00:00 2001 From: Steven Pautz Date: Sat, 12 Sep 2020 13:40:17 -0400 Subject: [PATCH] Cleanup and initial results --- README.md | 4 +++- benchmark/README.md | 20 ++++++++++---------- benchmark/options.js | 2 +- benchmark/run-benchmark.js | 2 +- benchmark/scenarios/scenario-utils.js | 2 +- benchmark/testObject.js | 2 ++ 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 00278cb..e7633da 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,6 @@ The original `state` is not modified. - If you're using [lodash](https://lodash.com) then you don't need this: [see this thread for alternatives](https://github.com/lodash/lodash/issues/1696#issuecomment-328335502). - The small bundle size of this library comes with a slight speed tradeoff. This library is a little slower than - immutable-assign and immutable.js, but a little faster than Immer and seamless-immutable. [See full benchmark here.](./benchmark) + immutable-assign and immutable.js, but a little faster than Immer and seamless-immutable. It's faster if you + use a string path instead of an array of path parts. + [See full benchmark here.](./benchmark) diff --git a/benchmark/README.md b/benchmark/README.md index 522131b..435aa27 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -16,16 +16,16 @@ yarn run benchmark; ## Results -Last run on (date goes here) - -| Library | Version | Bundle size | Time (lower is better) | -| :------------------------------------------------------------------------------ | ------------: | ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------: | -| [Immer](https://immerjs.github.io/immer/) | `7.0.8` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immer)](https://bundlephobia.com/result?p=immer) | (pending) | -| [Immutable.js](https://immutable-js.github.io/immutable-js/) | `4.0.0-rc.12` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immutable)](https://bundlephobia.com/result?p=immutable) | (pending) | -| [immutable-assign](https://github.com/engineforce/ImmutableAssign) (iassign.js) | `2.1.4` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immutable-assign)](https://bundlephobia.com/result?p=immutable-assign) | (pending) | -| [lodash](https://lodash.com/) (setWith + clone) | `4.17.20` | [![gzip size](https://img.shields.io/bundlephobia/minzip/lodash)](https://bundlephobia.com/result?p=lodash) | (pending) | -| [seamless-immutable](https://github.com/rtfeldman/seamless-immutable) | `7.1.4` | [![gzip size](https://img.shields.io/bundlephobia/minzip/seamless-immutable)](https://bundlephobia.com/result?p=seamless-immutable) | (pending) | -| [tiny-immutable-set](https://github.com/spautz/tiny-immutable-set) | `0.1.0` | [![gzip size](https://img.shields.io/bundlephobia/minzip/tiny-immutable-set)](https://bundlephobia.com/result?p=tiny-immutable-set) | (pending) | +Lower times are better .Last run on September 12, 2020. + +| Library | Version | Bundle size | **Total time** | ["prop1", "prop2", "prop3"] | "prop1.prop2.prop3" | "prop1[prop2][prop3]" | +| :------------------------------------------------------------------------------ | ------------: | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------: | --------------------------: | ------------------: | --------------------: | +| [Immer](https://immerjs.github.io/immer/) | `7.0.8` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immer@7.0.8)](https://bundlephobia.com/result?p=immer@7.0.8) | **27.447886964** | 8.907073234 | 9.249547088 | 9.291266642 | +| [Immutable.js](https://immutable-js.github.io/immutable-js/) | `4.0.0-rc.12` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immutable@4.0.0-rc.12)](https://bundlephobia.com/result?p=immutable@4.0.0-rc.12) | (pending) | (pending) | (pending) | (pending) | +| [immutable-assign](https://github.com/engineforce/ImmutableAssign) (iassign.js) | `2.1.4` | [![gzip size](https://img.shields.io/bundlephobia/minzip/immutable-assign@2.1.4)](https://bundlephobia.com/result?p=immutable-assign@2.1.4) | (pending) | (pending) | (pending) | (pending) | +| [lodash](https://lodash.com/) (setWith + clone) | `4.17.20` | [![gzip size](https://img.shields.io/bundlephobia/minzip/lodash@4.17.20)](https://bundlephobia.com/result?p=lodash@4.17.20) | **4.662552397** | 1.23424402 | 1.784842394 | 1.854285601 | +| [seamless-immutable](https://github.com/rtfeldman/seamless-immutable) | `7.1.4` | [![gzip size](https://img.shields.io/bundlephobia/minzip/seamless-immutable@7.1.4)](https://bundlephobia.com/result?p=seamless-immutable@7.1.4) | (pending) | (pending) | (pending) | (pending) | +| [tiny-immutable-set](https://github.com/spautz/tiny-immutable-set) | `0.1.0` | [![gzip size](https://img.shields.io/bundlephobia/minzip/tiny-immutable-set@0.1.0)](https://bundlephobia.com/result?p=tiny-immutable-set@0.1.0) | **4.702447091** | 2.191983945 | 1.447061770 | 1.63401376 | ## Organization diff --git a/benchmark/options.js b/benchmark/options.js index 9ea377c..a1eb9de 100644 --- a/benchmark/options.js +++ b/benchmark/options.js @@ -1,6 +1,6 @@ const options = { /* How many times each scenario is run for each library */ - numIterations: 10000, + numIterations: 100000, /* Whether to console.log while libraries and scenarios are running */ showLogs: true, /* Whether to console.warn if a library hasn't implemented a scenario */ diff --git a/benchmark/run-benchmark.js b/benchmark/run-benchmark.js index b6ada58..663c6ae 100644 --- a/benchmark/run-benchmark.js +++ b/benchmark/run-benchmark.js @@ -25,7 +25,7 @@ function formatTime(timeInfo) { const duration = `${seconds}.${nanoseconds}`; return duration; } - return '---'; + return '(no result)'; } // Create a timeline to track each (library,scenario) tuple diff --git a/benchmark/scenarios/scenario-utils.js b/benchmark/scenarios/scenario-utils.js index 30407d4..6cff508 100644 --- a/benchmark/scenarios/scenario-utils.js +++ b/benchmark/scenarios/scenario-utils.js @@ -47,7 +47,7 @@ function generateMissingPaths(object, numMissingPaths) { const path = getRandomPath(object); // And change one of the keys to something that [almost certainly] doesn't exist const indexToChange = Math.floor(Math.random() * path.length); - path.splice(indexToChange, 1, `rand${Math.random()}`); + path.splice(indexToChange, 1, `rand${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`); paths.push(path); } diff --git a/benchmark/testObject.js b/benchmark/testObject.js index bfbb010..aa1092f 100644 --- a/benchmark/testObject.js +++ b/benchmark/testObject.js @@ -40,4 +40,6 @@ for (let propNum = 0; propNum < TEST_OBJECT_BREADTH; propNum++) { } } +Object.freeze(TEST_OBJECT); + module.exports = TEST_OBJECT;