-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add AsyncIterable benchmarks (#361)
* Update benchmark code * Add AsyncIterable benchmarks * chore: fix lint errors * chore: add dev dependencies --------- Co-authored-by: Cayman <[email protected]>
- Loading branch information
1 parent
07b995c
commit 0ede9cd
Showing
7 changed files
with
140 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Mocha opts | ||
extension: ["ts"] | ||
colors: true | ||
node-option: | ||
- "loader=ts-node/register" | ||
|
||
# benchmark opts | ||
threshold: 3 | ||
maxMs: 60_000 | ||
minRuns: 10 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { itBench } from '@dapplion/benchmark' | ||
import { abortableSource } from 'abortable-iterator' | ||
import all from 'it-all' | ||
import { pipe } from 'it-pipe' | ||
|
||
/* eslint-disable generator-star-spacing */ | ||
|
||
describe('abortableSource cost', function () { | ||
const n = 10000 | ||
const bytes = new Uint8Array(200) | ||
const controller = new AbortController() | ||
|
||
async function* bytesSource (): AsyncGenerator<Uint8Array, void, unknown> { | ||
let i = 0 | ||
while (i++ < n) { | ||
yield bytes | ||
} | ||
} | ||
|
||
for (let k = 0; k < 5; k++) { | ||
itBench({ | ||
id: `async iterate abortable x${k} bytesSource ${n}`, | ||
beforeEach: () => { | ||
let source = bytesSource() | ||
for (let i = 0; i < k; i++) { | ||
source = abortableSource(source, controller.signal) | ||
} | ||
return source | ||
}, | ||
fn: async (source) => { | ||
for await (const chunk of source) { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions | ||
chunk | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
describe('pipe extra iterables cost', function () { | ||
const n = 10000 | ||
|
||
async function* numberSource (): AsyncGenerator<number, void, unknown> { | ||
let i = 0 | ||
while (i < n) { | ||
yield i++ | ||
} | ||
} | ||
|
||
async function* numberTransform (source: AsyncIterable<number>): AsyncIterable<number> { | ||
for await (const num of source) { | ||
yield num + 1 | ||
} | ||
} | ||
|
||
itBench({ | ||
id: `async iterate pipe x0 transforms ${n}`, | ||
fn: async () => { | ||
await pipe(numberSource, all) | ||
} | ||
}) | ||
|
||
itBench({ | ||
id: `async iterate pipe x1 transforms ${n}`, | ||
fn: async () => { | ||
await pipe(numberSource, numberTransform, all) | ||
} | ||
}) | ||
|
||
itBench({ | ||
id: `async iterate pipe x2 transforms ${n}`, | ||
fn: async () => { | ||
await pipe( | ||
numberSource, | ||
numberTransform, | ||
numberTransform, | ||
all | ||
) | ||
} | ||
}) | ||
|
||
itBench({ | ||
id: `async iterate pipe x4 transforms ${n}`, | ||
fn: async () => { | ||
await pipe( | ||
numberSource, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
all | ||
) | ||
} | ||
}) | ||
|
||
itBench({ | ||
id: `async iterate pipe x8 transforms ${n}`, | ||
fn: async () => { | ||
await pipe( | ||
numberSource, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
numberTransform, | ||
all | ||
) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters