Skip to content

Commit 016acb6

Browse files
committed
fix: make esm loader happy
1 parent 114d936 commit 016acb6

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

.github/workflows/codspeed.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CodSpeed Benchmarks
2+
3+
on:
4+
push:
5+
branches:
6+
- "main" # or "master"
7+
pull_request:
8+
# `workflow_dispatch` allows CodSpeed to trigger backtest
9+
# performance analysis in order to generate initial data.
10+
workflow_dispatch:
11+
12+
jobs:
13+
benchmarks:
14+
name: Run benchmarks
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: "actions/checkout@v4"
18+
- uses: "actions/setup-node@v3"
19+
- name: Install dependencies
20+
run: npm install
21+
- name: Run benchmarks
22+
uses: CodSpeedHQ/action@v3
23+
with:
24+
run: node benches/bench.mjs
25+
token: ${{ secrets.CODSPEED_TOKEN }}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
3535
"changelog": "node --loader ts-node/esm resources/gen-changelog.ts",
3636
"benchmark": "node --loader ts-node/esm resources/benchmark.ts",
37-
"codspeed": "node --loader ts-node/esm resources/tinybench.ts",
37+
"codspeed": "node --loader ts-node/esm resources/use-tinybench.ts",
3838
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
3939
"lint": "eslint --cache --max-warnings 0 --rulesdir resources/eslint-internal-rules/ .",
4040
"check": "tsc --pretty",

resources/codspeed-benchmarks.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { withCodSpeed } from '@codspeed/tinybench-plugin';
2+
import { Bench } from 'tinybench';
3+
import path from 'node:path';
4+
import fs from 'node:fs';
5+
6+
7+
async function loadBenchmarks() {
8+
const benchmarkDir = path.resolve('file:///var/folders/pb/xgxvrz094n7c09ltjpf6k0xm0000gq/T/graphql-js-benchmark/setup/local');
9+
const files = fs.readdirSync(benchmarkDir).filter(file => file.endsWith('-benchmark.js'));
10+
11+
const bench = withCodSpeed(new Bench());
12+
13+
for (const file of files) {
14+
const filePath = path.join(benchmarkDir, file);
15+
// eslint-disable-next-line no-await-in-loop
16+
const { benchmark } = await import(filePath);
17+
bench.add(benchmark.name, benchmark.measure);
18+
}
19+
20+
await bench.warmup();
21+
await bench.run();
22+
console.log(bench.table());
23+
}
24+
25+
console.log('Running benchmarks...');
26+
loadBenchmarks();

resources/tinybench.ts resources/use-tinybench.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import cp from 'node:child_process';
22
import fs from 'node:fs';
33
import path from 'node:path';
4-
import url from 'node:url';
54

65
import { git, localRepoPath, makeTmpDir, npm } from './utils.js';
76

@@ -94,14 +93,7 @@ function prepareBenchmarkProject(
9493
}
9594
}
9695

97-
interface BenchmarkSample {
98-
name: string;
99-
clocked: number;
100-
memUsed: number;
101-
involuntaryContextSwitches: number;
102-
}
103-
104-
function sampleModule(modulePath: string): BenchmarkSample {
96+
function sampleModule(modulePath: string): void {
10597
// To support Windows we need to use URL instead of path
10698
//const moduleURL = url.pathToFileURL(modulePath);
10799

0 commit comments

Comments
 (0)