66 lines
2.5 KiB
TypeScript
66 lines
2.5 KiB
TypeScript
import { bench, describe } from 'vitest';
|
|
import { STANDARD } from '../helpers/bench-options.js';
|
|
import {
|
|
okSome,
|
|
okNone,
|
|
errNone,
|
|
TsOk,
|
|
TsErr,
|
|
TsSome,
|
|
TsNone,
|
|
OxOk,
|
|
OxErr,
|
|
OxSome,
|
|
OxNone,
|
|
E,
|
|
O,
|
|
TmResult,
|
|
TmMaybe,
|
|
} from '../helpers/imports.js';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// OkSome — vs nested Result<Option<T>, E>
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Query construction — OkSome (primitive)', () => {
|
|
bench('native-monad', () => { okSome(42); }, STANDARD);
|
|
bench('ts-results-es (nested)', () => { TsOk(TsSome(42)); }, STANDARD);
|
|
bench('oxide.ts (nested)', () => { OxOk(OxSome(42)); }, STANDARD);
|
|
bench('fp-ts (nested)', () => { E.right(O.some(42)); }, STANDARD);
|
|
bench('true-myth (nested)', () => { TmResult.ok(TmMaybe.just(42)); }, STANDARD);
|
|
});
|
|
|
|
describe('Query construction — OkSome (object payload)', () => {
|
|
const value = { id: 1, name: 'Alice' };
|
|
|
|
bench('native-monad', () => { okSome(value); }, STANDARD);
|
|
bench('ts-results-es (nested)', () => { TsOk(TsSome(value)); }, STANDARD);
|
|
bench('oxide.ts (nested)', () => { OxOk(OxSome(value)); }, STANDARD);
|
|
bench('fp-ts (nested)', () => { E.right(O.some(value)); }, STANDARD);
|
|
bench('true-myth (nested)', () => { TmResult.ok(TmMaybe.just(value)); }, STANDARD);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// OkNone — vs nested Result<Option<T>, E>
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Query construction — OkNone (singleton)', () => {
|
|
bench('native-monad', () => { okNone(); }, STANDARD);
|
|
bench('ts-results-es (nested)', () => { TsOk(TsNone); }, STANDARD);
|
|
bench('oxide.ts (nested)', () => { OxOk(OxNone); }, STANDARD);
|
|
bench('fp-ts (nested)', () => { E.right(O.none); }, STANDARD);
|
|
bench('true-myth (nested)', () => { TmResult.ok(TmMaybe.nothing()); }, STANDARD);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ErrNone — vs nested Err
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Query construction — ErrNone', () => {
|
|
bench('native-monad', () => { errNone('fail'); }, STANDARD);
|
|
bench('ts-results-es (nested)', () => { TsErr('fail'); }, STANDARD);
|
|
bench('oxide.ts (nested)', () => { OxErr('fail'); }, STANDARD);
|
|
bench('fp-ts (nested)', () => { E.left('fail'); }, STANDARD);
|
|
bench('true-myth (nested)', () => { TmResult.err('fail'); }, STANDARD);
|
|
});
|