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