40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { bench, describe } from 'vitest';
|
|
import { STANDARD } from '../helpers/bench-options.js';
|
|
import {
|
|
Result,
|
|
ntFromThrowable,
|
|
E,
|
|
TmResult,
|
|
} from '../helpers/imports.js';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Result.from — success (no throw)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Result.from — success (no throw)', () => {
|
|
const fn = () => 42;
|
|
|
|
bench('native-monad', () => { Result.from(fn); }, STANDARD);
|
|
bench('neverthrow', () => { ntFromThrowable(fn)(); }, STANDARD);
|
|
bench('fp-ts', () => { E.tryCatch(fn, () => 'error'); }, STANDARD);
|
|
bench('true-myth', () => { TmResult.tryOr('error', fn); }, STANDARD);
|
|
// ts-results-es: no from/tryCatch
|
|
// oxide.ts: no from/tryCatch
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Result.from — failure (throws)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Result.from — failure (throws)', () => {
|
|
const thrower = () => {
|
|
throw new Error('fail');
|
|
};
|
|
const mapErr = () => 'error' as const;
|
|
|
|
bench('native-monad', () => { Result.from(thrower, mapErr); }, STANDARD);
|
|
bench('neverthrow', () => { ntFromThrowable(thrower, mapErr)(); }, STANDARD);
|
|
bench('fp-ts', () => { E.tryCatch(thrower, mapErr); }, STANDARD);
|
|
bench('true-myth', () => { TmResult.tryOr('error', thrower); }, STANDARD);
|
|
});
|