Skip to content

Commit 2f5c2e8

Browse files
committed
chore: add await sync() benchmark
1 parent 5540350 commit 2f5c2e8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ Run the following command to benchmark the performance of `quansync`:
6363
pnpm run build && pnpm run benchmark
6464
```
6565

66+
Benchmark results indicate that each `yield` incurs an overhead of
67+
approximately 150 ns, comparable to that of `await sync()`. (On Apple M1 Max)
68+
6669
## Build-time Macro
6770

6871
If you don't like the `function*` and `yield*` syntax, we also provide a build-time macro via [unplugin-quansync](https://github.com/unplugin/unplugin-quansync#usage) allowing you use quansync with async/await syntax, while still able to get the sync version out of that.

scripts/benchmark.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ summary(() => {
4141
bench('sync: native add', function* () {
4242
yield () => do_not_optimize(addNativeSync(1))
4343
})
44+
bench('sync: native await add', function* () {
45+
yield async () => do_not_optimize(await addNativeSync(1))
46+
})
4447
bench('sync: quansync add', function* () {
4548
yield () => do_not_optimize(quansyncAdd.sync(1))
4649
})
47-
bench('sync: gensync add ', function* () {
50+
bench('sync: gensync add', function* () {
4851
yield () => do_not_optimize(gensyncAdd.sync(1))
4952
})
5053
})
@@ -68,7 +71,7 @@ summary(() => {
6871
bench('async: quansync add', function* () {
6972
yield async () => do_not_optimize(await quansyncAdd.async(1))
7073
})
71-
bench('async: gensync add ', function* () {
74+
bench('async: gensync add', function* () {
7275
yield async () => do_not_optimize(await gensyncAdd.async(1))
7376
})
7477
})

0 commit comments

Comments
 (0)