Skip to content

Commit

Permalink
perf: improve concurrency defaults (inspired by Jest definitions) (#637)
Browse files Browse the repository at this point in the history
* ci: adapt benchmark values

* fix(perf): improve concurrency defaults (inspired by Jest definitions)

* fix(perf): use half of available parallelism in watch mode

* docs: adapt concurrency description
  • Loading branch information
wellwelwel committed Aug 1, 2024
1 parent 60958bd commit ab01530
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ To see the detailed documentation, please visit the [**Documentation**](https://

**Poku** is [continuously tested](https://github.com/wellwelwel/poku/blob/main/.github/workflows/ci_benchmark.yml) to ensure the following expectations for basic usage:

- \>=**4x** faster than [**Jest**](https://github.com/jestjs/jest) (v29.7.0)
- \>=**3x** faster than [**Vitest**](https://github.com/vitest-dev/vitest) (v1.6.0)
- \>=**1x** faster than [**Mocha**](https://github.com/mochajs/mocha) (v10.4.0) + [**Chai**](https://github.com/chaijs/chai) (v5.1.1)
- ~**4x** faster than [**Jest**](https://github.com/jestjs/jest) (v29.7.0)
- ~**3x** faster than [**Vitest**](https://github.com/vitest-dev/vitest) (v1.6.0)
- ~**1x** faster than [**Mocha**](https://github.com/mochajs/mocha) (v10.4.0) + [**Chai**](https://github.com/chaijs/chai) (v5.1.1)

> You can see how the tests are run and compared in the [benchmark](https://github.com/wellwelwel/poku/tree/main/benchmark) directory.
Expand Down
6 changes: 3 additions & 3 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The testers to be compared are chosen based on the three most downloaded test ru

**Poku** is continuously tested ([**CI**](https://github.com/wellwelwel/poku/blob/main/.github/workflows/ci_benchmark.yml)) to ensure the following expectations for basic usage:

- \>=**4x** faster than [**Jest**](https://github.com/jestjs/jest) (v29.7.0)
- \>=**3x** faster than [**Vitest**](https://github.com/vitest-dev/vitest) (v1.6.0)
- \>=**1x** faster than [**Mocha**](https://github.com/mochajs/mocha) (v10.4.0) + [**Chai**](https://github.com/chaijs/chai) (v5.1.1)
- ~**4x** faster than [**Jest**](https://github.com/jestjs/jest) (v29.7.0)
- ~**3x** faster than [**Vitest**](https://github.com/vitest-dev/vitest) (v1.6.0)
- ~**1x** faster than [**Mocha**](https://github.com/mochajs/mocha) (v10.4.0) + [**Chai**](https://github.com/chaijs/chai) (v5.1.1)

---

Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const test = () => {
const pokuResult = results.get('Poku (Local)');

const tolerancesPerTester = {
Jest: 4,
Jest: 3.9,
'Mocha + Chai': 1,
Vitest: 3,
Poku: 0.8,
Expand Down
8 changes: 7 additions & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { watch, type Watcher } from '../services/watch.js';
import { onSigint, poku } from '../modules/essentials/poku.js';
import { Write } from '../services/write.js';
import { getConfigs } from '../parsers/options.js';
import { availableParallelism } from '../polyfills/cpus.js';

(async () => {
const configFile = getArg('config') || getArg('c', '-');
Expand Down Expand Up @@ -215,7 +216,12 @@ import { getConfigs } from '../parsers/options.js';
return;
}

poku(Array.from(tests), options).then(() => {
poku(Array.from(tests), {
...options,
concurrency:
concurrency ??
Math.max(Math.floor(availableParallelism() / 2), 1),
}).then(() => {
setTimeout(() => {
executing.delete(filePath);
}, interval);
Expand Down
2 changes: 1 addition & 1 deletion src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const runTestsParallel = async (
const files = await listFiles(testDir, configs);
const filesByConcurrency: string[][] = [];
const concurrencyLimit =
configs?.concurrency ?? Math.max(Math.floor(availableParallelism() / 2), 1);
configs?.concurrency ?? Math.max(availableParallelism() - 1, 1);
const concurrencyResults: (boolean | undefined)[][] = [];
const showLogs = !isQuiet(configs);

Expand Down
6 changes: 3 additions & 3 deletions website/docs/comparing.mdx