Files
native-monad/benchmarks/option/type-guards.bench.ts
2026-03-30 08:34:35 +02:00

67 lines
2.1 KiB
TypeScript

import { bench, describe } from 'vitest';
import { STANDARD } from '../helpers/bench-options.js';
import {
some,
none,
TsSome,
TsNone,
OxSome,
OxNone,
O,
TmMaybe,
} from '../helpers/imports.js';
// ---------------------------------------------------------------------------
// isSome — on Some
// ---------------------------------------------------------------------------
describe('Option.isSome — on Some', () => {
const nm = some(42);
const ts = TsSome(42);
const ox = OxSome(42);
const fp = O.some(42);
const tm = TmMaybe.just(42);
bench('native-monad', () => { nm.isSome(); }, STANDARD);
bench('ts-results-es', () => { ts.isSome(); }, STANDARD);
bench('oxide.ts', () => { ox.isSome(); }, STANDARD);
bench('fp-ts', () => { O.isSome(fp); }, STANDARD);
bench('true-myth', () => { tm.isJust; }, STANDARD);
});
// ---------------------------------------------------------------------------
// isSome — on None
// ---------------------------------------------------------------------------
describe('Option.isSome — on None', () => {
const nm = none();
const ts = TsNone;
const ox = OxNone;
const fp = O.none;
const tm = TmMaybe.nothing<number>();
bench('native-monad', () => { nm.isSome(); }, STANDARD);
bench('ts-results-es', () => { ts.isSome(); }, STANDARD);
bench('oxide.ts', () => { ox.isSome(); }, STANDARD);
bench('fp-ts', () => { O.isSome(fp); }, STANDARD);
bench('true-myth', () => { tm.isJust; }, STANDARD);
});
// ---------------------------------------------------------------------------
// isNone — on None
// ---------------------------------------------------------------------------
describe('Option.isNone — on None', () => {
const nm = none();
const ts = TsNone;
const ox = OxNone;
const fp = O.none;
const tm = TmMaybe.nothing<number>();
bench('native-monad', () => { nm.isNone(); }, STANDARD);
bench('ts-results-es', () => { ts.isNone(); }, STANDARD);
bench('oxide.ts', () => { ox.isNone(); }, STANDARD);
bench('fp-ts', () => { O.isNone(fp); }, STANDARD);
bench('true-myth', () => { tm.isNothing; }, STANDARD);
});