Skip to content

Commit

Permalink
Update bench
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl committed Mar 11, 2024
1 parent 961b2c1 commit 6849f2a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
24 changes: 14 additions & 10 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ Tested on a M1 Pro MacBook Pro.
## Option

```
fp-ts Option none x 130,955,745 ops/sec ±1.11% (98 runs sampled)
fp-ts Option some x 97,400,638 ops/sec ±0.26% (100 runs sampled)
fp-ts Option some chain x 2,776,666 ops/sec ±0.16% (97 runs sampled)
Boxed Option none x 1,030,036,990 ops/sec ±0.13% (100 runs sampled)
Boxed Option some x 461,820,063 ops/sec ±0.20% (101 runs sampled)
Boxed Option some flatMap x 461,736,015 ops/sec ±0.32% (97 runs sampled)
fp-ts Option none x 133,199,621 ops/sec ±0.88% (95 runs sampled)
fp-ts Option some x 94,608,143 ops/sec ±1.02% (95 runs sampled)
fp-ts Option some chain x 2,704,227 ops/sec ±1.19% (96 runs sampled)
effect Option none x 27,023,109 ops/sec ±1.29% (88 runs sampled)
effect Option some x 24,754,366 ops/sec ±1.15% (93 runs sampled)
effect Option some chain x 23,508,577 ops/sec ±0.79% (92 runs sampled)
Boxed Option none x 1,021,669,460 ops/sec ±0.87% (100 runs sampled)
Boxed Option some x 455,095,023 ops/sec ±1.37% (97 runs sampled)
Boxed Option some flatMap x 461,052,470 ops/sec ±1.00% (96 runs sampled)
```

## Result

```
fp-ts Result x 117,922,535 ops/sec ±0.39% (98 runs sampled)
Boxed Result x 465,661,918 ops/sec ±0.21% (101 runs sampled)
fp-ts Result x 116,286,025 ops/sec ±0.81% (95 runs sampled)
effect Result x 25,582,523 ops/sec ±0.80% (99 runs sampled)
Boxed Result x 439,563,425 ops/sec ±1.00% (99 runs sampled)
```

## Future

Careful on the interpretation of the following, as Future doesn't use microtasks and calls its listeners synchronously.

```
Future x 38,364,199 ops/sec ±0.68% (92 runs sampled)
Promise x 13,482,385 ops/sec ±0.25% (90 runs sampled)
Future x 37,910,965 ops/sec ±1.02% (90 runs sampled)
Promise x 12,620,204 ops/sec ±1.74% (83 runs sampled)
```
25 changes: 25 additions & 0 deletions benchmark/src/option.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Benchmark = require("benchmark");
const fp = require("fp-ts");
const effect = require("effect");
const { Option } = require("../../dist/Boxed");

const suite = new Benchmark.Suite();
Expand Down Expand Up @@ -28,6 +29,30 @@ suite.add("fp-ts Option some chain", () => {
);
});

suite.add("effect Option none", () => {
return effect.pipe(
effect.Option.fromNullable(null),
effect.Option.map((x) => x * 2),
effect.Option.orElse(() => 10),
);
});

suite.add("effect Option some", () => {
return effect.pipe(
effect.Option.fromNullable(10),
effect.Option.map((x) => x * 2),
effect.Option.orElse(() => 10),
);
});

suite.add("effect Option some chain", () => {
return effect.pipe(
effect.Option.fromNullable(10),
effect.Option.flatMap((x) => effect.Option.some(x * 2)),
effect.Option.orElse(() => 10),
);
});

suite.add("Boxed Option none", () => {
return Option.fromNullable(null)
.map((x) => x * 2)
Expand Down
9 changes: 9 additions & 0 deletions benchmark/src/result.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Benchmark = require("benchmark");
const fp = require("fp-ts");
const effect = require("effect");
const { Result } = require("../../dist/Boxed");

const suite = new Benchmark.Suite();
Expand All @@ -12,6 +13,14 @@ suite.add("fp-ts Result", () => {
);
});

suite.add("effect Result", () => {
return effect.pipe(
effect.Either.right(1),
effect.Either.map((x) => x * 2),
effect.Either.orElse(() => 10),
);
});

suite.add("Boxed Result", () => {
return Result.Ok(1)
.map((x) => x * 2)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"@types/benchmark": "^2.1.5",
"benchmark": "^2.1.4",
"effect": "^2.4.3",
"fp-ts": "^2.16.1",
"microbundle": "^0.15.1",
"prettier": "^3.1.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,11 @@ duplexer@^0.1.1, duplexer@^0.1.2:
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"
integrity sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==

effect@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/effect/-/effect-2.4.3.tgz#c447bb7020fd45154a2e9d216e45e5323531b744"
integrity sha512-OmIgfNgQMZsQt5l7qLQqLOUxIXq7ku8/RK3Wv3LqxSE2zMyU1mHXof5QeyCt7m9sXv3Vui52Urk1vVsEd2szMQ==

ejs@^3.1.6:
version "3.1.9"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.9.tgz#03c9e8777fe12686a9effcef22303ca3d8eeb361"
Expand Down

0 comments on commit 6849f2a

Please sign in to comment.