-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo): setup codspeed for benchmarking
- Loading branch information
1 parent
202b49b
commit 4c61f0d
Showing
9 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/nx/src/command-line/run-many/run-many.benchmark.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { Bench } from 'tinybench'; | ||
|
||
import { projectsToRun } from './run-many'; | ||
import { ProjectGraph } from '../../config/project-graph'; | ||
|
||
let projectGraph: ProjectGraph = { | ||
nodes: { | ||
proj1: { | ||
name: 'proj1', | ||
type: 'lib', | ||
data: { | ||
root: 'proj1', | ||
tags: ['api', 'theme1'], | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
}, | ||
}, | ||
}, | ||
proj2: { | ||
name: 'proj2', | ||
type: 'lib', | ||
data: { | ||
root: 'proj2', | ||
tags: ['ui', 'theme2'], | ||
targets: { | ||
test: {}, | ||
}, | ||
}, | ||
}, | ||
} as any, | ||
dependencies: {}, | ||
}; | ||
|
||
for (let i = 0; i < 1000000; i++) { | ||
projectGraph.nodes['proj' + i] = { | ||
name: 'proj' + i, | ||
type: 'lib', | ||
data: { | ||
root: 'proj' + i, | ||
targets: { | ||
test: {}, | ||
}, | ||
} as any, | ||
}; | ||
} | ||
|
||
export function registerBenchmarks(bench: Bench) { | ||
return bench.add( | ||
'should be able to select and exclude via patterns', | ||
async () => { | ||
projectsToRun( | ||
{ | ||
targets: ['test'], | ||
projects: ['proj1*'], | ||
exclude: ['proj12*'], | ||
}, | ||
projectGraph | ||
); | ||
}, | ||
{} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": [ | ||
"**/*.spec.ts", | ||
"**/*_spec.ts", | ||
"jest.config.ts", | ||
"**/__fixtures__/**/*.*", | ||
"./src/internal-testing-utils/**/*.ts" | ||
], | ||
"include": ["**/*.benchmark.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { join } from 'node:path'; | ||
import { Bench, Fn } from 'tinybench'; | ||
import { withCodSpeed } from '@codspeed/tinybench-plugin'; | ||
|
||
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context'; | ||
import { workspaceRoot } from '../../packages/nx/src/utils/workspace-root'; | ||
|
||
export function findAllBenchmarks(root: string) { | ||
return globWithWorkspaceContext(workspaceRoot, [ | ||
join(root, '**', '*.benchmark.ts'), | ||
]); | ||
} | ||
|
||
export async function runAllBenchmarks(root: string) { | ||
const bench = withCodSpeed(new Bench()); | ||
|
||
const benchmarks = await findAllBenchmarks(root); | ||
|
||
for (const benchmarkFile of benchmarks) { | ||
const m = require(join('../../', benchmarkFile)) as { | ||
registerBenchmarks?: (bench: Bench) => void; | ||
}; | ||
if (m.registerBenchmarks) { | ||
m.registerBenchmarks(bench); | ||
} else { | ||
throw new Error(`No benchmarks found in ${benchmarkFile}`); | ||
} | ||
} | ||
const results = await bench.run(); | ||
console.table(bench.table()); | ||
const errors = results.map((s) => s.result?.error).filter(Boolean); | ||
if (errors.length) { | ||
throw new AggregateError(errors); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
const root = process.argv[2] || '.'; | ||
runAllBenchmarks(root) | ||
.then(() => { | ||
console.log('All benchmarks completed.'); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error('Error running benchmarks:', err); | ||
process.exit(1); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "../../build/bench-out", | ||
"module": "commonjs", | ||
"types": ["node"] | ||
}, | ||
"include": ["../../**/*.ts"] | ||
} |