Skip to content

Commit

Permalink
Minor README tweaks
Browse files Browse the repository at this point in the history
* Call out fancy `toMapGroupBy` function.
* Mention Node version in benchmarks.
* Extra note about Ramda in benchmarks.
  • Loading branch information
dphilipson committed Jun 21, 2018
1 parent 04b02a1 commit 0065c3d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Provide an API for using transducers that is…
which operations you will be using, and then let your bundler (such as Webpack
4+ or Rollup) strip out the parts you aren't using, reducing the size cost to
well below 4 kB. See the section on
[tree-shaking](#bundle-size-and-treeshaking) for stats and details.
[tree-shaking](#bundle-size-and-tree-shaking) for stats and details.

## Installation

Expand Down Expand Up @@ -128,8 +128,8 @@ Import with
```ts
import { chainFrom } from "transducist";
```
Start a chain by calling `chainFrom()` on any iterable, including an array or a
string.
Start a chain by calling `chainFrom()` on any iterable, such as an array, a
string, or an ES6 `Set`.
```ts
const result = chainFrom(["a", "bb", "ccc", "dddd", "eeeee"])
```
Expand All @@ -145,7 +145,8 @@ chain and produces a result.
.toArray(); // -> ["A", "CCC"]
```
Other terminating methods include `.forEach()`, `.count()`, and `.find()`, among
others.
others. For a particularly interesting one, see
[`.toMapGroupBy()`](https://github.com/dphilipson/transducist/blob/master/docs/api.md#tomapgroupbygetkey-transformer).

For a list of all possible transformations and terminations, [see the full API
docs](https://github.com/dphilipson/transducist/blob/master/docs/api.md#api).
Expand Down Expand Up @@ -253,7 +254,7 @@ import { filter, map, toArray, transduce } from "transducist";
transduce(
[1, 2, 3, 4, 5],
compose(
filter((x: number) => x > 2),
filter(x => x > 2),
map(x => 2 * x),
),
toArray(),
Expand All @@ -276,7 +277,7 @@ those are the only functions in use, compared chained version which has a
bundled size of 11.1 kB (as of version 0.4.0, minified).

For details, [see the tree-shaking
API](https://github.com/dphilipson/transducist/blob/master/docs/api.md#treeshaking-api)
API](https://github.com/dphilipson/transducist/blob/master/docs/api.md#tree-shakeable-api)
section of the API docs.

## Benchmarks
Expand Down
21 changes: 10 additions & 11 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ chainFrom(authors).toMap(a => a.id, a => a.books.length);

### `.toMapGroupBy(getKey, transformer?)`

Produces an ES6 `Map` by grouping together under each key all elements for which
`getKey` returned that key. By default, each key corresponds to an array of the
elements which produced that key.
Produces an ES6 `Map` by grouping together all elements for which `getKey`
returns the same value under that key. By default, each key corresponds to an
array of the elements which produced that key.

Optionally, a transformer may be passed as the second argument to configure the
reduction behavior of the values. All chain ending methods in this secion other
reduction behavior of the values. All chain-ending methods in this section other
than `.toIterator()` have a standalone variant which produces a transformer (for
details, see the section [Tree-shakeable API](#tree-shakeable-api)), which opens
many possibilities. Some advanced examples are shown below.
Expand Down Expand Up @@ -475,12 +475,12 @@ chainFrom(authors).toObject(a => a.id, a => a.books.length);

### `.toObjectGroupBy(getKey, transformer?)`

Produces an object by grouping together under each key all elements for which
`getKey` returned that key. By default, each key corresponds to an array of the
elements which produced that key.
Produces an object by grouping together all elements for which `getKey` returns
the same value under that key. By default, each key corresponds to an array of
the elements which produced that key.

Optionally, a transformer may be passed as the second argument to configure the
reduction behavior of the values. All chain ending methods in this secion other
reduction behavior of the values. All chain-ending methods in this section other
than `.toIterator()` have a standalone variant which produces a transformer (for
details, see the section [Tree-shakeable API](#tree-shakeable-api)), which opens
many possibilities. Some advanced examples are shown below.
Expand Down Expand Up @@ -709,7 +709,7 @@ import { filter, map, toArray, transduce } from "transducist";
transduce(
[1, 2, 3, 4, 5],
compose(
filter((x: number) => x > 2),
filter(x => x > 2),
map(x => 2 * x),
),
toArray(),
Expand Down Expand Up @@ -739,10 +739,9 @@ import { filter, map, lazyTransduce } from "transducist";
lazyTransduce(
[1, 2, 3, 4, 5],
compose(
filter((x: number) => x > 2),
filter(x => x > 2),
map(x => 2 * x),
),
toArray(),
);
```
```ts
Expand Down
26 changes: 17 additions & 9 deletions docs/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Description

These benchmarks were generated by running a computation equivalent to the
following in various libraries on a 2015 MacBook Pro:
following in various libraries on Node 10.40.0 on a 2015 MacBook Pro:

```ts
chainFrom([1, 2, /** ... */, n])
Expand All @@ -22,6 +22,9 @@ chainFrom([1, 2, /** ... */, n])
.toArray();
```

The benchmark source code can be found
[here](https://github.com/dphilipson/transducist-benchmarks/blob/master/src/index.ts).

## Results

```
Expand All @@ -34,7 +37,7 @@ ramda x 476,214 ops/sec ±0.55% (93 runs sampled)
lazy.js x 2,652,169 ops/sec ±1.22% (90 runs sampled)
transducers.js x 1,099,321 ops/sec ±0.60% (90 runs sampled)
transducers-js x 687,221 ops/sec ±0.96% (93 runs sampled)
Array#map(), Array#filter() x 3,685,880 ops/sec ±0.45% (94 runs sampled)
native array methods x 3,685,880 ops/sec ±0.45% (94 runs sampled)
hand-optimized loop x 19,250,719 ops/sec ±2.01% (89 runs sampled)
n = 100
Expand All @@ -46,7 +49,7 @@ ramda x 196,973 ops/sec ±0.84% (87 runs sampled)
lazy.js x 478,335 ops/sec ±0.57% (94 runs sampled)
transducers.js x 235,804 ops/sec ±0.69% (92 runs sampled)
transducers-js x 164,375 ops/sec ±0.64% (92 runs sampled)
Array#map(), Array#filter() x 195,732 ops/sec ±0.58% (94 runs sampled)
native array methods x 195,732 ops/sec ±0.58% (94 runs sampled)
hand-optimized loop x 2,654,405 ops/sec ±0.57% (89 runs sampled)
n = 1,000
Expand All @@ -58,7 +61,7 @@ ramda x 27,283 ops/sec ±0.80% (92 runs sampled)
lazy.js x 56,104 ops/sec ±0.66% (94 runs sampled)
transducers.js x 25,595 ops/sec ±0.88% (89 runs sampled)
transducers-js x 19,098 ops/sec ±0.65% (94 runs sampled)
Array#map(), Array#filter() x 19,179 ops/sec ±0.67% (91 runs sampled)
native array methods x 19,179 ops/sec ±0.67% (91 runs sampled)
hand-optimized loop x 247,362 ops/sec ±1.25% (90 runs sampled)
n = 10,000
Expand All @@ -70,7 +73,7 @@ ramda x 2,980 ops/sec ±0.65% (93 runs sampled)
lazy.js x 5,921 ops/sec ±0.61% (93 runs sampled)
transducers.js x 2,724 ops/sec ±0.43% (94 runs sampled)
transducers-js x 1,910 ops/sec ±0.93% (93 runs sampled)
Array#map(), Array#filter() x 1,873 ops/sec ±0.92% (91 runs sampled)
native array methods x 1,873 ops/sec ±0.92% (91 runs sampled)
hand-optimized loop x 26,402 ops/sec ±0.58% (91 runs sampled)
n = 100,000
Expand All @@ -82,7 +85,7 @@ ramda x 186 ops/sec ±1.17% (78 runs sampled)
lazy.js x 594 ops/sec ±0.72% (90 runs sampled)
transducers.js x 244 ops/sec ±0.52% (87 runs sampled)
transducers-js x 184 ops/sec ±0.65% (84 runs sampled)
Array#map(), Array#filter() x 33.03 ops/sec ±0.85% (57 runs sampled)
native array methods x 33.03 ops/sec ±0.85% (57 runs sampled)
hand-optimized loop x 2,428 ops/sec ±0.34% (96 runs sampled)
```

Expand All @@ -94,10 +97,15 @@ hand-optimized loop x 2,428 ops/sec ±0.34% (96 runs sampled)
other libraries tested. In particular, its performance is close to that of
[Ramda](https://ramdajs.com/) and
[transducers.js](https://github.com/jlongster/transducers.js/).
* [Lodash](https://lodash.com/) performed surprisingly poorly, and its chaining
benchmarks showed no sign of optimization at high element count.
* Note, however, that while Ramda has comparable performance on this benchmark
task, its typical usage does not provide short-circuiting. In particular, if
the task were changed to add a `.take(10)` at the end of the chain, then
Transducist would complete nearly instantly while Ramda would take just as
long.
* [Lodash](https://lodash.com/) performed surprisingly poorly, and its chained
API is slower than its non-chained one at all element counts.
* Native array methods are fast at low element counts, but are overtaken by
chaining libraries at around 100 elements.
* Of course, the fastest of all is writing an optimized loop by hand, which is
around 5x as fast as Lazy.js and 10x as fast as the other competitive
roughly 5x as fast as Lazy.js and 10x as fast as the other competitive
libraries.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"test": "yarn run lint && tsc && yarn run jest"
},
"lint-staged": {
"*.json": [
"*.{js,json}": [
"yarn run format",
"git add"
],
Expand Down

0 comments on commit 0065c3d

Please sign in to comment.