Skip to content

Commit

Permalink
chore: migrate CLI execution to execa
Browse files Browse the repository at this point in the history
  • Loading branch information
FRSgit committed Jan 5, 2025
1 parent 9243c63 commit 477c1e8
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 105 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,17 @@ const result = sync({
### input as glob pattern [40 files]

| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |
| --- | --- | --- | --- |
| 1 | @frsource/frs-replace (async) | 0.63 ± 2.61% | +0.00% |
| 2 | @frsource/frs-replace (sync) | 0.69 ± 0.84% | +9.48% |
| 3 | replace-in-file (async) | 0.80 ± 1.14% | +28.41% |
| 4 | replace-in-file (async) | 0.88 ± 1.49% | +40.16% |
| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |
| ---- | ----------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| 1 | @frsource/frs-replace (async) | 0.63 ± 1.11% | +0.00% |
| 2 | @frsource/frs-replace (sync) | 0.72 ± 0.76% | +14.38% |
| 3 | replace-in-file (async) | 0.85 ± 0.74% | +33.88% |
| 4 | replace-in-file (async) | 0.92 ± 1.36% | +44.73% |

### input & replacement as strings

| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |
| --- | --- | --- | --- |
| 1 | @frsource/frs-replace (sync) | 0.00 ± 0.31% | +0.00% |
| 2 | @frsource/frs-replace (async) | 0.01 ± 0.38% | +13.63% |
| 3 | replaceString | 0.03 ± 0.73% | +560.57% |
| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |
| ---- | ----------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| 1 | @frsource/frs-replace (sync) | 0.01 ± 0.33% | +0.00% |
| 2 | @frsource/frs-replace (async) | 0.01 ± 0.32% | +12.15% |
| 3 | replaceString | 0.03 ± 0.72% | +517.31% |
43 changes: 42 additions & 1 deletion benchmark/compare-bench-results.bench-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
import { expect, test } from 'vitest';
import { afterAll, expect, test } from 'vitest';
import { readFileSync, writeFileSync } from 'fs';
import results from './results.json';

afterAll(updateReadmeBenchmarkContent);

results.files[0].groups.forEach(({ fullName, benchmarks }) => {
const testName = fullName.split(' > ').slice(1).join(' > ');
test(`${testName} > frs-replace should be the fastest framework`, () => {
const sortedResults = benchmarks.sort((a, b) => a.rank - b.rank);
expect(sortedResults[0].name).toContain('frs-replace');
});
});

function updateReadmeBenchmarkContent() {
let benchResultsContent = '';
for (const testGroup of results.files[0].groups) {
const groupName = testGroup.fullName.split(' > ').slice(1).join(' > ');
benchResultsContent +=
'\n### ' +
groupName +
'\n\n' +
'| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |\n' +
'| --- | --- | --- | --- |\n' +
testGroup.benchmarks
.sort((a, b) => a.rank - b.rank)
.reduce(
(p, v) =>
p +
'| ' +
v.rank +
' | ' +
v.name +
' | ' +
`${v.mean.toFixed(2)} \xb1 ${v.rme.toFixed(2)}%` +
' | ' +
`+${((v.mean / testGroup.benchmarks[0].mean - 1) * 100).toFixed(2)}%` +
' |\n',
'',
);
}

const readmeContent = readFileSync('./README.md')
.toString()
.replace(
/(##\s:chart_with_upwards_trend:\sBenchmarks)[\s\S]*?(?:$|(?:\s##\s))/,
`$1\n\n> Tested on Node ${process.version}.\n${benchResultsContent}`,
);

writeFileSync('./README.md', readmeContent);
}
40 changes: 1 addition & 39 deletions benchmark/multiple-file-replace.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { FileResult, dirSync, file } from 'tmp-promise';
import { afterAll, beforeAll, bench, describe } from 'vitest';
import { sync } from 'fast-glob';
import { readFileSync, unlinkSync, writeFileSync } from 'fs';
import { unlinkSync } from 'fs';
import { appendFile } from 'fs/promises';

const regex = /'^[adjox]/gm;
Expand Down Expand Up @@ -51,44 +51,6 @@ beforeAll(async () => {
afterAll(async () => {
inputs.forEach((input) => input.cleanup);
inputs = [];

const { default: benchResults } = await import('./results.json');

let benchResultsContent = '';
for (const testGroup of benchResults.files[0].groups) {
const groupName = testGroup.fullName.split(' > ').slice(1).join(' > ');
benchResultsContent +=
'\n### ' +
groupName +
'\n\n' +
'| Rank | Library | Average latency [ms] | Difference percentage (comparing to best average latency) |\n' +
'| --- | --- | --- | --- |\n' +
testGroup.benchmarks
.sort((a, b) => a.rank - b.rank)
.reduce(
(p, v) =>
p +
'| ' +
v.rank +
' | ' +
v.name +
' | ' +
`${v.mean.toFixed(2)} \xb1 ${v.rme.toFixed(2)}%` +
' | ' +
`+${((v.mean / testGroup.benchmarks[0].mean - 1) * 100).toFixed(2)}%` +
' |\n',
'',
);
}

const readmeContent = readFileSync('./README.md')
.toString()
.replace(
/(##\s:chart_with_upwards_trend:\sBenchmarks)[\s\S]*?(?:$|(?:\s##\s))/,
`$1\n\n> Tested on Node ${process.version}.\n${benchResultsContent}`,
);

writeFileSync('./README.md', readmeContent);
});

describe(`input as glob pattern [${inputFilesNo} files]`, () => {
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { sync } from '../dist/index.mjs';

(process.env.CI || ~process.argv.indexOf('--no-stdin')
(~process.argv.indexOf('--no-stdin')
? Promise.resolve()
: (await import('get-stdin')).default()
).then(async (stdin) => {
Expand Down
Loading

0 comments on commit 477c1e8

Please sign in to comment.