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

60 lines
2.2 KiB
TypeScript

import { bench, describe } from 'vitest';
import { STANDARD } from '../helpers/bench-options.js';
import {
Option,
O,
TmMaybe,
} from '../helpers/imports.js';
// ---------------------------------------------------------------------------
// Option.from — non-nullish value
// ---------------------------------------------------------------------------
describe('Option.from — non-nullish value', () => {
bench('native-monad', () => { Option.from(42); }, STANDARD);
bench('fp-ts', () => { O.fromNullable(42); }, STANDARD);
bench('true-myth', () => { TmMaybe.of(42); }, STANDARD);
});
// ---------------------------------------------------------------------------
// Option.from — null value
// ---------------------------------------------------------------------------
describe('Option.from — null', () => {
bench('native-monad', () => { Option.from(null); }, STANDARD);
bench('fp-ts', () => { O.fromNullable(null); }, STANDARD);
bench('true-myth', () => { TmMaybe.of(null); }, STANDARD);
});
// ---------------------------------------------------------------------------
// Option.from — undefined value
// ---------------------------------------------------------------------------
describe('Option.from — undefined', () => {
bench('native-monad', () => { Option.from(undefined); }, STANDARD);
bench('fp-ts', () => { O.fromNullable(undefined); }, STANDARD);
bench('true-myth', () => { TmMaybe.of(undefined); }, STANDARD);
});
// ---------------------------------------------------------------------------
// Option.from — function that returns value
// ---------------------------------------------------------------------------
describe('Option.from — function returning value', () => {
const fn = () => 42;
bench('native-monad', () => { Option.from(fn); }, STANDARD);
// fp-ts: no function overload for fromNullable
// true-myth: no function overload for of
});
// ---------------------------------------------------------------------------
// Option.from — function that returns null
// ---------------------------------------------------------------------------
describe('Option.from — function returning null', () => {
const fn = () => null;
bench('native-monad', () => { Option.from(fn); }, STANDARD);
});