Skip to content

Commit

Permalink
chore: fix benchmark issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 21, 2024
1 parent efa6e3d commit a749ba3
Show file tree
Hide file tree
Showing 10 changed files with 16,635 additions and 12,537 deletions.
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
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' │
└───────────┴────────────┴──────────────┴───────────────────┴─────────────┴─────────────────┴───────────────────┴────────────────────────┴───────────┴─────────────────┘
4 changes: 3 additions & 1 deletion benchmarks/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const perfCase = async name => {
const loadStartTime = performance.now()

const { default: syncFn } = await import(
`./${name}.${name === 'synckit' || name === 'make-synchronized' ? 'js' : 'cjs'}`
`./${name}.${
name === 'synckit' || name === 'make-synchronized' ? 'js' : 'cjs'
}`
)

const loadTime = performance.now() - loadStartTime
Expand Down
8 changes: 6 additions & 2 deletions benchmarks/make-synchronized.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { makeSynchronized } = require('make-synchronized')

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

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

/** @type {() => string} */
const syncFn = makeSynchronized(new URL('native.cjs', import.meta.url))

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

export default syncFn
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,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,6 +68,7 @@
"@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",
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

0 comments on commit a749ba3

Please sign in to comment.