initial commit
This commit is contained in:
39
benchmarks/result/from-wrapping.bench.ts
Normal file
39
benchmarks/result/from-wrapping.bench.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user