Skip to content

Commit 9ed752b

Browse files
fiskerJounQin
andauthored
chore: add make-synchronized to benchmark test (#160)
Co-authored-by: JounQin <[email protected]>
1 parent 69b8dcd commit 9ed752b

File tree

11 files changed

+549
-677
lines changed

11 files changed

+549
-677
lines changed

.codesandbox/ci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"node": "18",
3+
"installCommand": "codesandbox:install",
34
"sandboxes": []
45
}

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
enableHardenedMode: false
2+
13
nodeLinker: node-modules
24

35
plugins:

benchmarks/benchmark.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ console.table(
9191
synckit: perfCase('synckit'),
9292
syncThreads: perfCase('sync-threads'),
9393
deasync: perfCase('deasync'),
94+
makeSynchronized: perfCase('make-synchronized'),
9495
native: perfCase('native'),
9596
}),
9697
)

benchmarks/benchmark.cjs.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
$ node benchmarks/benchmark.cjs
2-
┌───────────┬────────────┬──────────────┬───────────────────┬────────────┬────────────────┬───────────┬─────────────────┐
3-
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ native │ perf native │
4-
├───────────┼────────────┼──────────────┼───────────────────┼────────────┼────────────────┼───────────┼─────────────────┤
5-
│ loadTime │ '9.01ms' │ '0.80ms' │ '11.29x slower' │ '20.32ms' │ '2.26x faster' │ '0.37ms' │ '24.37x slower' │
6-
│ runTime │ '109.97ms' │ '5166.40ms' │ '46.98x faster' │ '557.75ms' │ '5.07x faster' │ '10.56ms' │ '10.41x slower' │
7-
│ totalTime │ '118.98ms' │ '5167.20ms' │ '43.43x faster' │ '578.07ms' │ '4.86x faster' │ '10.93ms' │ '10.88x slower' │
8-
└───────────┴────────────┴──────────────┴───────────────────┴────────────┴────────────────┴───────────┴─────────────────┘
1+
┌───────────┬────────────┬──────────────┬───────────────────┬─────────────┬─────────────────┬───────────────────┬────────────────────────┬───────────┬─────────────────┐
2+
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ make-synchronized │ perf make-synchronized │ native │ perf native │
3+
├───────────┼────────────┼──────────────┼───────────────────┼─────────────┼─────────────────┼───────────────────┼────────────────────────┼───────────┼─────────────────┤
4+
│ loadTime │ '7.24ms' │ '0.80ms' │ '9.02x slower' │ '134.41ms' │ '18.56x faster' │ '1.52ms' │ '4.77x slower' │ '0.45ms' │ '16.24x slower' │
5+
│ runTime │ '104.63ms' │ '5822.64ms' │ '55.65x faster' │ '3945.29ms' │ '37.71x faster' │ '153.68ms' │ '1.47x faster' │ '9.86ms' │ '10.61x slower' │
6+
│ totalTime │ '111.87ms' │ '5823.44ms' │ '52.06x faster' │ '4079.69ms' │ '36.47x faster' │ '155.20ms' │ '1.39x faster' │ '10.31ms' │ '10.85x slower' │
7+
└───────────┴────────────┴──────────────┴───────────────────┴─────────────┴─────────────────┴───────────────────┴────────────────────────┴───────────┴─────────────────┘

benchmarks/benchmark.esm.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
$ node benchmarks/benchmark.js
2-
┌───────────┬────────────┬──────────────┬───────────────────┬────────────┬────────────────┬───────────┬─────────────────┐
3-
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ native │ perf native │
4-
├───────────┼────────────┼──────────────┼───────────────────┼────────────┼────────────────┼───────────┼─────────────────┤
5-
│ loadTime │ '16.97ms' │ '1.04ms' │ '16.37x slower' │ '9.67ms' │ '1.76x slower' │ '0.56ms' │ '30.19x slower' │
6-
│ runTime │ '122.19ms' │ '4970.21ms' │ '40.67x faster' │ '633.51ms' │ '5.18x faster' │ '10.47ms' │ '11.67x slower' │
7-
│ totalTime │ '139.16ms' │ '4971.25ms' │ '35.72x faster' │ '643.18ms' │ '4.62x faster' │ '11.03ms' │ '12.61x slower' │
8-
└───────────┴────────────┴──────────────┴───────────────────┴────────────┴────────────────┴───────────┴─────────────────┘
1+
┌───────────┬────────────┬──────────────┬───────────────────┬─────────────┬─────────────────┬───────────────────┬────────────────────────┬───────────┬─────────────────┐
2+
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ make-synchronized │ perf make-synchronized │ native │ perf native │
3+
├───────────┼────────────┼──────────────┼───────────────────┼─────────────┼─────────────────┼───────────────────┼────────────────────────┼───────────┼─────────────────┤
4+
│ loadTime │ '14.26ms' │ '1.07ms' │ '13.26x slower' │ '60.57ms' │ '4.25x faster' │ '1.22ms' │ '11.64x slower' │ '0.40ms' │ '35.34x slower' │
5+
│ runTime │ '118.02ms' │ '6435.42ms' │ '54.53x faster' │ '3745.86ms' │ '31.74x faster' │ '155.31ms' │ '1.32x faster' │ '10.87ms' │ '10.86x slower' │
6+
│ totalTime │ '132.28ms' │ '6436.49ms' │ '48.66x faster' │ '3806.43ms' │ '28.78x faster' │ '156.54ms' │ '1.18x faster' │ '11.27ms' │ '11.74x slower' │
7+
└───────────┴────────────┴──────────────┴───────────────────┴─────────────┴─────────────────┴───────────────────┴────────────────────────┴───────────┴─────────────────┘

benchmarks/benchmark.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const __filename = fileURLToPath(import.meta.url)
1515
const perfCase = async name => {
1616
const loadStartTime = performance.now()
1717

18-
const syncFn =
19-
// eslint-disable-next-line unicorn/no-await-expression-member
20-
(await import(`./${name}.${name === 'synckit' ? 'js' : 'cjs'}`)).default
18+
const { default: syncFn } = await import(
19+
`./${name}.${
20+
name === 'synckit' || name === 'make-synchronized' ? 'js' : 'cjs'
21+
}`
22+
)
2123

2224
const loadTime = performance.now() - loadStartTime
2325

@@ -96,6 +98,7 @@ console.table(
9698
synckit: await perfCase('synckit'),
9799
syncThreads: await perfCase('sync-threads'),
98100
deasync: await perfCase('deasync'),
101+
makeSynchronized: await perfCase('make-synchronized'),
99102
native: await perfCase('native'),
100103
}),
101104
)

benchmarks/make-synchronized.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { makeSynchronized } = require('make-synchronized')
2+
3+
/**
4+
* @param {string} filename
5+
* @returns {() => string} syncified function
6+
*/
7+
const syncFn = filename =>
8+
makeSynchronized('node:fs/promises').readFile(filename, 'utf8')
9+
10+
module.exports = syncFn

benchmarks/make-synchronized.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { makeSynchronized } from 'make-synchronized'
2+
3+
/**
4+
* @param {string} filename
5+
* @returns {() => string} syncified function
6+
*/
7+
const syncFn = filename =>
8+
makeSynchronized('node:fs/promises').readFile(filename, 'utf8')
9+
10+
export default syncFn

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"keywords": [
2727
"deasync",
28+
"make-synchronized",
2829
"make-synchronous",
2930
"sync",
3031
"sync-exec",
@@ -35,14 +36,15 @@
3536
],
3637
"scripts": {
3738
"benchmark": "concurrently -r -m 1 'yarn:benchmark:*'",
38-
"benchmark-export": "concurrently -r -m 1 'yarn:benchmark-export:*'",
39+
"benchmark-export": "cross-env FORCE_COLOR=0 concurrently -r -m 1 'yarn:benchmark-export:*'",
3940
"benchmark-export:cjs": "yarn benchmark:cjs > benchmarks/benchmark.cjs.txt",
4041
"benchmark-export:esm": "yarn benchmark:esm> benchmarks/benchmark.esm.txt",
4142
"benchmark:cjs": "node benchmarks/benchmark.cjs",
4243
"benchmark:esm": "node benchmarks/benchmark.js",
4344
"build": "concurrently -r 'yarn:build:*'",
4445
"build:r": "r -f cjs",
4546
"build:ts": "tsc -p src",
47+
"codesandbox:install": "yarn --ignore-engines",
4648
"lint": "concurrently -r 'yarn:lint:*'",
4749
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
4850
"lint:tsc": "tsc --noEmit",
@@ -67,13 +69,15 @@
6769
"@types/node": "^20.10.6",
6870
"clean-pkg-json": "^1.2.0",
6971
"concurrently": "^8.2.2",
72+
"cross-env": "^7.0.3",
7073
"deasync": "^0.1.29",
7174
"esbuild-register": "^3.5.0",
7275
"esbuild-runner": "^2.2.2",
7376
"eslint": "^8.56.0",
7477
"execa": "^8.0.1",
7578
"jest": "^29.7.0",
7679
"lint-staged": "^15.2.0",
80+
"make-synchronized": "^0.0.3",
7781
"node-gyp": "^10.0.1",
7882
"patch-package": "^8.0.0",
7983
"prettier": "^3.1.1",

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ export type Syncify<T extends AnyAsyncFn> = T extends (
1515
? (...args: Args) => R
1616
: never
1717

18-
export type PromiseType<T extends AnyPromise> = T extends Promise<infer R>
19-
? R
20-
: never
18+
export type PromiseType<T extends AnyPromise> =
19+
T extends Promise<infer R> ? R : never
2120

2221
export type ValueOf<T> = T[keyof T]
2322

0 commit comments

Comments
 (0)