43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { bench, describe } from 'vitest';
|
|
import { EXTENDED } from '../helpers/bench-options.js';
|
|
import {
|
|
some,
|
|
none,
|
|
OptionPromise,
|
|
} from '../helpers/imports.js';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// OptionPromise.from — returns value
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('OptionPromise.from — returns value', () => {
|
|
bench('native-monad', async () => {
|
|
await OptionPromise.from(() => Promise.resolve(42));
|
|
}, EXTENDED);
|
|
// No other library has an async Option wrapper
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// OptionPromise.from — returns null
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('OptionPromise.from — returns null', () => {
|
|
bench('native-monad', async () => {
|
|
await OptionPromise.from(() => Promise.resolve(null));
|
|
}, EXTENDED);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// OptionPromise.all — all Some
|
|
// ---------------------------------------------------------------------------
|
|
|
|
for (const size of [10, 100] as const) {
|
|
describe(`OptionPromise.all — ${size} items, all Some`, () => {
|
|
const promises = () => Array.from({ length: size }, (_, i) => Promise.resolve(some(i)));
|
|
|
|
bench('native-monad', async () => {
|
|
await OptionPromise.all(promises());
|
|
}, EXTENDED);
|
|
});
|
|
}
|