Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add make-synchronized to benchmark test #160

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"node": "18",
"installCommand": "codesandbox:install",
"sandboxes": []
}
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enableHardenedMode: false

nodeLinker: node-modules

plugins:
Expand Down
1 change: 1 addition & 0 deletions benchmarks/benchmark.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ console.table(
synckit: perfCase('synckit'),
syncThreads: perfCase('sync-threads'),
deasync: perfCase('deasync'),
makeSynchronized: perfCase('make-synchronized'),
native: perfCase('native'),
}),
)
15 changes: 7 additions & 8 deletions benchmarks/benchmark.cjs.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
$ node benchmarks/benchmark.cjs
┌───────────┬────────────┬──────────────┬───────────────────┬────────────┬────────────────┬───────────┬─────────────────┐
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ native │ perf native │
├───────────┼────────────┼──────────────┼───────────────────┼────────────┼────────────────┼───────────┼─────────────────┤
│ loadTime │ '9.01ms' │ '0.80ms' │ '11.29x slower' │ '20.32ms' │ '2.26x faster' │ '0.37ms' │ '24.37x slower' │
│ runTime │ '109.97ms' │ '5166.40ms' │ '46.98x faster' │ '557.75ms' │ '5.07x faster' │ '10.56ms' │ '10.41x slower' │
│ totalTime │ '118.98ms' │ '5167.20ms' │ '43.43x faster' │ '578.07ms' │ '4.86x faster' │ '10.93ms' │ '10.88x slower' │
└───────────┴────────────┴──────────────┴───────────────────┴────────────┴────────────────┴───────────┴─────────────────┘
┌───────────┬────────────┬──────────────┬───────────────────┬─────────────┬─────────────────┬───────────────────┬────────────────────────┬───────────┬─────────────────┐
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ make-synchronized │ perf make-synchronized │ native │ perf native │
├───────────┼────────────┼──────────────┼───────────────────┼─────────────┼─────────────────┼───────────────────┼────────────────────────┼───────────┼─────────────────┤
│ loadTime │ '7.24ms' │ '0.80ms' │ '9.02x slower' │ '134.41ms' │ '18.56x faster' │ '1.52ms' │ '4.77x slower' │ '0.45ms' │ '16.24x slower' │
│ runTime │ '104.63ms' │ '5822.64ms' │ '55.65x faster' │ '3945.29ms' │ '37.71x faster' │ '153.68ms' │ '1.47x faster' │ '9.86ms' │ '10.61x slower' │
│ totalTime │ '111.87ms' │ '5823.44ms' │ '52.06x faster' │ '4079.69ms' │ '36.47x faster' │ '155.20ms' │ '1.39x faster' │ '10.31ms' │ '10.85x slower' │
└───────────┴────────────┴──────────────┴───────────────────┴─────────────┴─────────────────┴───────────────────┴────────────────────────┴───────────┴─────────────────┘
15 changes: 7 additions & 8 deletions benchmarks/benchmark.esm.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
$ node benchmarks/benchmark.js
┌───────────┬────────────┬──────────────┬───────────────────┬────────────┬────────────────┬───────────┬─────────────────┐
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ native │ perf native │
├───────────┼────────────┼──────────────┼───────────────────┼────────────┼────────────────┼───────────┼─────────────────┤
│ loadTime │ '16.97ms' │ '1.04ms' │ '16.37x slower' │ '9.67ms' │ '1.76x slower' │ '0.56ms' │ '30.19x slower' │
│ runTime │ '122.19ms' │ '4970.21ms' │ '40.67x faster' │ '633.51ms' │ '5.18x faster' │ '10.47ms' │ '11.67x slower' │
│ totalTime │ '139.16ms' │ '4971.25ms' │ '35.72x faster' │ '643.18ms' │ '4.62x faster' │ '11.03ms' │ '12.61x slower' │
└───────────┴────────────┴──────────────┴───────────────────┴────────────┴────────────────┴───────────┴─────────────────┘
┌───────────┬────────────┬──────────────┬───────────────────┬─────────────┬─────────────────┬───────────────────┬────────────────────────┬───────────┬─────────────────┐
│ (index) │ synckit │ sync-threads │ perf sync-threads │ deasync │ perf deasync │ make-synchronized │ perf make-synchronized │ native │ perf native │
├───────────┼────────────┼──────────────┼───────────────────┼─────────────┼─────────────────┼───────────────────┼────────────────────────┼───────────┼─────────────────┤
│ loadTime │ '14.26ms' │ '1.07ms' │ '13.26x slower' │ '60.57ms' │ '4.25x faster' │ '1.22ms' │ '11.64x slower' │ '0.40ms' │ '35.34x slower' │
│ runTime │ '118.02ms' │ '6435.42ms' │ '54.53x faster' │ '3745.86ms' │ '31.74x faster' │ '155.31ms' │ '1.32x faster' │ '10.87ms' │ '10.86x slower' │
│ totalTime │ '132.28ms' │ '6436.49ms' │ '48.66x faster' │ '3806.43ms' │ '28.78x faster' │ '156.54ms' │ '1.18x faster' │ '11.27ms' │ '11.74x slower' │
└───────────┴────────────┴──────────────┴───────────────────┴─────────────┴─────────────────┴───────────────────┴────────────────────────┴───────────┴─────────────────┘
9 changes: 6 additions & 3 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const __filename = fileURLToPath(import.meta.url)
const perfCase = async name => {
const loadStartTime = performance.now()

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

const loadTime = performance.now() - loadStartTime

Expand Down Expand Up @@ -96,6 +98,7 @@ console.table(
synckit: await perfCase('synckit'),
syncThreads: await perfCase('sync-threads'),
deasync: await perfCase('deasync'),
makeSynchronized: await perfCase('make-synchronized'),
native: await perfCase('native'),
}),
)
10 changes: 10 additions & 0 deletions benchmarks/make-synchronized.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { makeSynchronized } = require('make-synchronized')

/**
* @param {string} filename
* @returns {() => string} syncified function
*/
const syncFn = filename =>
makeSynchronized('node:fs/promises').readFile(filename, 'utf8')

module.exports = syncFn
10 changes: 10 additions & 0 deletions benchmarks/make-synchronized.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { makeSynchronized } from 'make-synchronized'

/**
* @param {string} filename
* @returns {() => string} syncified function
*/
const syncFn = filename =>
makeSynchronized('node:fs/promises').readFile(filename, 'utf8')

export default syncFn
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"keywords": [
"deasync",
"make-synchronized",
"make-synchronous",
"sync",
"sync-exec",
Expand All @@ -35,14 +36,15 @@
],
"scripts": {
"benchmark": "concurrently -r -m 1 'yarn:benchmark:*'",
"benchmark-export": "concurrently -r -m 1 'yarn:benchmark-export:*'",
"benchmark-export": "cross-env FORCE_COLOR=0 concurrently -r -m 1 'yarn:benchmark-export:*'",
"benchmark-export:cjs": "yarn benchmark:cjs > benchmarks/benchmark.cjs.txt",
"benchmark-export:esm": "yarn benchmark:esm> benchmarks/benchmark.esm.txt",
"benchmark:cjs": "node benchmarks/benchmark.cjs",
"benchmark:esm": "node benchmarks/benchmark.js",
"build": "concurrently -r 'yarn:build:*'",
"build:r": "r -f cjs",
"build:ts": "tsc -p src",
"codesandbox:install": "yarn --ignore-engines",
"lint": "concurrently -r 'yarn:lint:*'",
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
"lint:tsc": "tsc --noEmit",
Expand All @@ -67,13 +69,15 @@
"@types/node": "^20.10.6",
"clean-pkg-json": "^1.2.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"deasync": "^0.1.29",
"esbuild-register": "^3.5.0",
"esbuild-runner": "^2.2.2",
"eslint": "^8.56.0",
"execa": "^8.0.1",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"make-synchronized": "^0.0.3",
"node-gyp": "^10.0.1",
"patch-package": "^8.0.0",
"prettier": "^3.1.1",
Expand Down
5 changes: 2 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export type Syncify<T extends AnyAsyncFn> = T extends (
? (...args: Args) => R
: never

export type PromiseType<T extends AnyPromise> = T extends Promise<infer R>
? R
: never
export type PromiseType<T extends AnyPromise> =
T extends Promise<infer R> ? R : never

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

Expand Down
Loading