Skip to content

Commit

Permalink
Cleanup and initial results
Browse files Browse the repository at this point in the history
  • Loading branch information
spautz committed Sep 12, 2020
1 parent 222158c commit b0ab864
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -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)
20 changes: 10 additions & 10 deletions benchmark/README.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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 */
Expand Down
2 changes: 1 addition & 1 deletion benchmark/run-benchmark.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scenarios/scenario-utils.js
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions benchmark/testObject.js
Expand Up @@ -40,4 +40,6 @@ for (let propNum = 0; propNum < TEST_OBJECT_BREADTH; propNum++) {
}
}

Object.freeze(TEST_OBJECT);

module.exports = TEST_OBJECT;

0 comments on commit b0ab864

Please sign in to comment.