Skip to content

Commit

Permalink
add optics-ts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 10, 2021
1 parent 2db6477 commit ecc6279
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"import-path-rewrite": "github:gcanti/import-path-rewrite",
"jest": "^24.3.0",
"mocha": "^5.2.0",
"optics-ts": "^2.1.0",
"partial.lenses": "^14.17.0",
"prettier": "^2.0.2",
"rimraf": "^2.6.3",
Expand Down
59 changes: 49 additions & 10 deletions perf/119.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,38 @@ import * as T from '../src/Traversal'
import { Traversable } from 'fp-ts/ReadonlyArray'
import { pipe } from 'fp-ts/function'
const PL = require('partial.lenses')
import * as O from 'optics-ts'

/*
prism into array (monocle-ts, stable APIs) x 1,140 ops/sec ±0.49% (87 runs sampled)
prism into array (monocle-ts, experimental APIs) x 958 ops/sec ±3.06% (86 runs sampled)
prism into array (partial.lenses) x 460,357 ops/sec ±0.46% (89 runs sampled)
prism modify array (monocle-ts, stable APIs) x 1,320 ops/sec ±0.64% (86 runs sampled)
prism modify array (monocle-ts, experimental APIs) x 1,423 ops/sec ±3.40% (84 runs sampled)
prism modify array (partial.lenses) x 2,329 ops/sec ±0.49% (87 runs sampled)
size = 5000
prism into array (monocle-ts, stable APIs) x 1,123 ops/sec ±0.37% (87 runs sampled)
prism into array (monocle-ts, experimental APIs) x 951 ops/sec ±2.18% (86 runs sampled)
prism into array (partial.lenses) x 451,070 ops/sec ±1.17% (89 runs sampled)
prism into array (optics-ts) x 10,672 ops/sec ±2.82% (84 runs sampled)
prism modify array (monocle-ts, stable APIs) x 1,336 ops/sec ±0.61% (89 runs sampled)
prism modify array (monocle-ts, experimental APIs) x 1,251 ops/sec ±2.06% (87 runs sampled)
prism modify array (partial.lenses) x 2,191 ops/sec ±2.12% (81 runs sampled)
prism modify array (optics-ts) x 3,763 ops/sec ±0.51% (92 runs sampled)
size = 500
prism into array (monocle-ts, stable APIs) x 10,328 ops/sec ±7.12% (87 runs sampled)
prism into array (monocle-ts, experimental APIs) x 9,230 ops/sec ±0.41% (91 runs sampled)
prism into array (partial.lenses) x 466,256 ops/sec ±0.49% (86 runs sampled)
prism into array (optics-ts) x 105,339 ops/sec ±0.45% (94 runs sampled)
prism modify array (monocle-ts, stable APIs) x 13,290 ops/sec ±1.53% (82 runs sampled)
prism modify array (monocle-ts, experimental APIs) x 12,911 ops/sec ±0.64% (88 runs sampled)
prism modify array (partial.lenses) x 30,039 ops/sec ±0.45% (91 runs sampled)
prism modify array (optics-ts) x 37,777 ops/sec ±0.46% (90 runs sampled)
size = 50
prism into array (monocle-ts, stable APIs) x 95,180 ops/sec ±10.31% (89 runs sampled)
prism into array (monocle-ts, experimental APIs) x 87,631 ops/sec ±0.39% (90 runs sampled)
prism into array (partial.lenses) x 462,813 ops/sec ±0.27% (90 runs sampled)
prism into array (optics-ts) x 558,323 ops/sec ±0.46% (91 runs sampled)
prism modify array (monocle-ts, stable APIs) x 111,160 ops/sec ±0.63% (88 runs sampled)
prism modify array (monocle-ts, experimental APIs) x 113,941 ops/sec ±0.59% (86 runs sampled)
prism modify array (partial.lenses) x 200,423 ops/sec ±0.56% (87 runs sampled)
prism modify array (optics-ts) x 251,464 ops/sec ±0.37% (90 runs sampled)
*/

const suite = new Benchmark.Suite()
Expand Down Expand Up @@ -74,13 +98,22 @@ const traversalPartialLenses = PL.compose(

const foldPartialLenses = PL.compose(traversalPartialLenses, PL.valueOr(undefined))

const nameModified = 'Luke-' + mid + '-modified'

const traversalMonocleExperimentalModify = pipe(
traversalMonocleExperimental,
T.modify((s) => ({ ...s, name: nameModified }))
)

const traversalOpticsTs = O.optic<typeof data>()
.prop('m')
.prop('n')
.prop('names')
.elems()
// `item` here has type: `NotAnArrayType<readonly Child[]>`, not sure what it means

This comment has been minimized.

Copy link
@akheron

akheron Jun 18, 2021

It means that .elems() doesn't understand that ReadonlyArray is also an array. This should be fixed in optics-ts side.

.when((item: any) => item.id === id)

const nameModified = 'Luke-' + mid + '-modified'
const f = (c: Child): Child => ({ ...c, name: nameModified })

suite
.add('prism into array (monocle-ts, stable APIs)', function () {
foldMonocleStable.headOption(data)
Expand All @@ -91,14 +124,20 @@ suite
.add('prism into array (partial.lenses)', function () {
PL.get(foldPartialLenses, data)
})
.add('prism into array (optics-ts)', function () {
O.preview(traversalOpticsTs)(data)
})
.add('prism modify array (monocle-ts, stable APIs)', function () {
traversalMonocleStable.modify((s) => ({ ...s, name: nameModified }))(data)
traversalMonocleStable.modify(f)(data)
})
.add('prism modify array (monocle-ts, experimental APIs)', function () {
traversalMonocleExperimentalModify(data)
})
.add('prism modify array (partial.lenses)', function () {
PL.modify(traversalPartialLenses, (s: Child) => ({ ...s, name: nameModified }), data)
PL.modify(traversalPartialLenses, f, data)
})
.add('prism modify array (optics-ts)', function () {
O.modify(traversalOpticsTs)(f as any)(data)
})
.on('cycle', function (event: any) {
// tslint:disable-next-line: no-console
Expand Down

0 comments on commit ecc6279

Please sign in to comment.