Files
native-monad/benchmarks/query/async.bench.ts
2026-03-30 08:34:35 +02:00

43 lines
1.4 KiB
TypeScript

import { bench, describe } from 'vitest';
import { EXTENDED } from '../helpers/bench-options.js';
import {
okSome,
okNone,
QueryPromise,
} from '../helpers/imports.js';
// ---------------------------------------------------------------------------
// QueryPromise.from — returns value
// ---------------------------------------------------------------------------
describe('QueryPromise.from — returns value', () => {
bench('native-monad', async () => {
await QueryPromise.from(() => Promise.resolve(42));
}, EXTENDED);
// No other library has a three-state async wrapper
});
// ---------------------------------------------------------------------------
// QueryPromise.from — returns null
// ---------------------------------------------------------------------------
describe('QueryPromise.from — returns null', () => {
bench('native-monad', async () => {
await QueryPromise.from(() => Promise.resolve(null));
}, EXTENDED);
});
// ---------------------------------------------------------------------------
// QueryPromise.all — all OkSome
// ---------------------------------------------------------------------------
for (const size of [10, 100] as const) {
describe(`QueryPromise.all — ${size} items, all OkSome`, () => {
const promises = () => Array.from({ length: size }, (_, i) => Promise.resolve(okSome(i)));
bench('native-monad', async () => {
await QueryPromise.all(promises());
}, EXTENDED);
});
}