Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/node_modules
node_modules
/.tshy
/lib
/dist
Expand Down
38 changes: 38 additions & 0 deletions bench/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {packageUp, packageUpSync} from 'package-up';
import {up as empathic} from 'empathic/package';
import {findPackagePath, findPackagePathSync} from 'fd-package-json';
import {Bench} from 'tinybench';
import {join} from 'node:path';
import {styleText} from 'node:util';

const dirs = 'abcdefghij';
const depths = [1, 3, 5, 10];

for (const dep of depths) {
const name = `${dep} depth${dep === 1 ? '' : 's'}`;
const cwd = join(import.meta.dirname, 'fixture', ...dirs.substring(0, dep));
const bench = new Bench({name, warmup: true});

bench
.add('package-up', async () => await packageUp({cwd}))
.add('package-up (sync)', () => packageUpSync({cwd}))
.add('empathic (sync)', () => empathic({cwd}))
.add('fd-package-json', async () => await findPackagePath(cwd))
.add('fd-package-json (sync)', () => findPackagePathSync(cwd));

await bench.run();

console.log(`# ${name}`);

const table = bench.table();
for (const row of table) {
for (const prop in row) {
const isName = prop === 'Task name';
console.log(
`${isName ? '-' : ' '} ${isName ? '' : `${prop}: `}${styleText(isName ? ['bold', 'underline'] : 'none', String(row[prop]))}`
);
}
}

console.log('');
}
Empty file.
15 changes: 15 additions & 0 deletions bench/fixture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "simple-package",
"private": true,
"version": "1.0.0",
"description": "A simple package that does nothing.",
"keywords": [
"some",
"keywords"
],
"author": "That Guy",
"license": "MIT",
"type": "module",
"dependencies": {
}
}
88 changes: 88 additions & 0 deletions bench/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "bench",
"private": true,
"type": "module",
"devDependencies": {
"empathic": "^2.0.0",
"fd-package-json": "file:../",
"package-up": "^5.0.0",
"tinybench": "^5.1.0"
}
}