48 lines
1.7 KiB
TypeScript
48 lines
1.7 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';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Some construction
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Option construction — Some (primitive)', () => {
|
|
bench('native-monad', () => { some(42); }, STANDARD);
|
|
// neverthrow: no Option type
|
|
bench('ts-results-es', () => { TsSome(42); }, STANDARD);
|
|
bench('oxide.ts', () => { OxSome(42); }, STANDARD);
|
|
bench('fp-ts', () => { O.some(42); }, STANDARD);
|
|
bench('true-myth', () => { TmMaybe.just(42); }, STANDARD);
|
|
});
|
|
|
|
describe('Option construction — Some (object payload)', () => {
|
|
const value = { id: 1, name: 'Alice', roles: ['admin', 'user'] };
|
|
|
|
bench('native-monad', () => { some(value); }, STANDARD);
|
|
bench('ts-results-es', () => { TsSome(value); }, STANDARD);
|
|
bench('oxide.ts', () => { OxSome(value); }, STANDARD);
|
|
bench('fp-ts', () => { O.some(value); }, STANDARD);
|
|
bench('true-myth', () => { TmMaybe.just(value); }, STANDARD);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// None construction / access
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Option construction — None', () => {
|
|
bench('native-monad', () => { none(); }, STANDARD);
|
|
bench('ts-results-es', () => { TsNone; }, STANDARD);
|
|
bench('oxide.ts', () => { OxNone; }, STANDARD);
|
|
bench('fp-ts', () => { O.none; }, STANDARD);
|
|
bench('true-myth', () => { TmMaybe.nothing(); }, STANDARD);
|
|
});
|