diff --git a/benchmark/README.md b/benchmark/README.md index 4dcd47d..72d83d7 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -5,19 +5,23 @@ 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 @@ -25,6 +29,6 @@ Boxed Result x 465,661,918 ops/sec ±0.21% (101 runs sampled) 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) ``` diff --git a/benchmark/src/option.js b/benchmark/src/option.js index fee90d3..8d3287a 100644 --- a/benchmark/src/option.js +++ b/benchmark/src/option.js @@ -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(); @@ -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) diff --git a/benchmark/src/result.js b/benchmark/src/result.js index b516afb..7991fde 100644 --- a/benchmark/src/result.js +++ b/benchmark/src/result.js @@ -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(); @@ -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) diff --git a/package.json b/package.json index 94dfc77..abe0286 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 0a2d6a8..774bb73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"