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
18 changes: 1 addition & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,15 @@ jobs:
needs: list-examples
strategy:
matrix:
node-version: ["14", "16", "18", "20"]
node-version: ["16", "18", "20.5.1"]
example: ${{ fromJson(needs.list-examples.outputs.examples) }}
include:
# tinybench does not support node 14
- node-version: "14"
pnpm-version: "7"
skip-tinybench: true
exclude:
# esbuild-register does not work well with node 14
- node-version: "14"
example: with-typescript-cjs
- node-version: "14"
example: with-typescript-esm
- node-version: "14"
example: with-typescript-simple-esm
fail-fast: false
steps:
- uses: "actions/checkout@v3"
with:
fetch-depth: 0
- run: sudo apt-get install -y valgrind
- uses: pnpm/action-setup@v2
with:
version: ${{ matrix.pnpm-version || '' }}
- uses: actions/setup-node@v3
with:
cache: pnpm
Expand All @@ -73,7 +58,6 @@ jobs:
- run: pnpm moon run :build

- name: Run benchmarks with tinybench-plugin
if: matrix.skip-tinybench != true
# use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v1`
uses: CodSpeedHQ/action@main
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
pnpm moon run --concurrency 1 :bench
pnpm --workspace-concurrency 1 -r bench-tinybench
pnpm --workspace-concurrency 1 -r bench-benchmark-js
pnpm --workspace-concurrency 1 -r bench-vitest
5 changes: 3 additions & 2 deletions .moon/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ tasks:
- "/.eslintrc.js"
- "tsconfig.json"
- "tsconfig.*.json"
deps:
- "build"

typecheck:
command: "tsc --noEmit --pretty"
Expand All @@ -45,7 +47,7 @@ tasks:
- "/tsconfig.json"
- "/tsconfig.base.json"
deps:
- "^:build"
- "build"

build:
command: "rollup -c rollup.config.ts --configPlugin typescript"
Expand All @@ -55,7 +57,6 @@ tasks:
outputs:
- "dist/"
deps:
- "typecheck"
- "^:build"
env:
NODE_NO_WARNINGS: "1"
Expand Down
7 changes: 0 additions & 7 deletions .moon/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
$schema: "https://moonrepo.dev/schemas/toolchain.json"

node:
version: 18.16.0
syncVersionManagerConfig: "nvm"
addEnginesConstraint: true

packageManager: "pnpm"
pnpm:
version: "8.6.3"

aliasPackageNames: "name-only"

dedupeOnLockfileChange: false
dependencyVersionFormat: "workspace"

inferTasksFromScripts: true

syncProjectWorkspaceDependencies: true

typescript:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Check out the [documentation](https://docs.codspeed.io/benchmarks/nodejs) for co

This mono-repo contains the integration packages for using CodSpeed with Node.js:

- [`@codspeed/vitest-plugin`](./packages/vitest-plugin): vitest compatibility layer for CodSpeed
- [`@codspeed/tinybench-plugin`](./packages/tinybench-plugin): tinybench compatibility layer for CodSpeed
- [`@codspeed/benchmark.js-plugin`](./packages/benchmark.js-plugin): Benchmark.js compatibility layer for CodSpeed
- [`@codspeed/core`](./packages/core): The core library used to integrate with Codspeed runners
15 changes: 15 additions & 0 deletions docs/introspection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Testing introspection locally

1. Inside `codspeed-node` directory, run `export PATH="$pwd/../action/dist/bin:$PATH"`.
This will ensure that the action's `dist/bin/node` file will be used instead of the
system's `node` binary.

2. Replace the `CodSpeedHQ/action` grep filter with `CodSpeedHQ` in the `dist/bin/node`.
Since we used `../action` in the `export PATH=...` command, the original grep filter will
not work.

3. Run your command with the correct flags in `codspeed-node`, for example

```bash
CI=1 CODSPEED_DEBUG=true pnpm --filter with-typescript-esm bench-tinybench
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WithCodSpeedSuite } from "@codspeed/benchmark.js-plugin";
import { aBaz, baz } from "../../src/foobarbaz";
import { baz } from "../../src/foobarbaz";

export function registerFoobarbazBenchmarks(suite: WithCodSpeedSuite) {
suite
Expand All @@ -9,12 +9,4 @@ export function registerFoobarbazBenchmarks(suite: WithCodSpeedSuite) {
.add("test sync baz 100", () => {
baz(100);
});

suite
.add("test async baz 10", async () => {
await aBaz(10);
})
.add("test async baz 100", async () => {
await aBaz(100);
});
}
10 changes: 1 addition & 9 deletions examples/with-typescript-cjs/bench/tinybench/foobarbaz.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bench } from "tinybench";
import { aBaz, baz } from "../../src/foobarbaz";
import { baz } from "../../src/foobarbaz";

export function registerFoobarbazBenchmarks(bench: Bench) {
bench
Expand All @@ -9,12 +9,4 @@ export function registerFoobarbazBenchmarks(bench: Bench) {
.add("test sync baz 100", () => {
baz(100);
});

bench
.add("test async baz 10", async () => {
await aBaz(10);
})
.add("test async baz 100", async () => {
await aBaz(100);
});
}
28 changes: 0 additions & 28 deletions examples/with-typescript-cjs/src/foobarbaz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,3 @@ function bar(n: number) {
export function baz(n: number) {
bar(n);
}

// Async version
function dummyThingToAwait() {
return new Promise<void>((resolve) => {
process.nextTick(() => {
resolve();
});
});
}

async function aFoo(n: number) {
await dummyThingToAwait();
let result = 0;
for (let i = 0; i < n; i++) {
result += 1;
}
return result;
}

async function aBar(n: number) {
await dummyThingToAwait();
await aFoo(n);
}

export async function aBaz(n: number) {
await dummyThingToAwait();
await aBar(n);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WithCodSpeedSuite } from "@codspeed/benchmark.js-plugin";
import { aBaz, baz } from "../../src/foobarbaz";
import { baz } from "../../src/foobarbaz";

export function registerFoobarbazBenchmarks(suite: WithCodSpeedSuite) {
suite
Expand All @@ -9,12 +9,4 @@ export function registerFoobarbazBenchmarks(suite: WithCodSpeedSuite) {
.add("test sync baz 100", () => {
baz(100);
});

suite
.add("test async baz 10", async () => {
await aBaz(10);
})
.add("test async baz 100", async () => {
await aBaz(100);
});
}
10 changes: 1 addition & 9 deletions examples/with-typescript-esm/bench/tinybench/foobarbaz.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bench } from "tinybench";
import { aBaz, baz } from "../../src/foobarbaz";
import { baz } from "../../src/foobarbaz";

export function registerFoobarbazBenchmarks(bench: Bench) {
bench
Expand All @@ -9,12 +9,4 @@ export function registerFoobarbazBenchmarks(bench: Bench) {
.add("test sync baz 100", () => {
baz(100);
});

bench
.add("test async baz 10", async () => {
await aBaz(10);
})
.add("test async baz 100", async () => {
await aBaz(100);
});
}
7 changes: 5 additions & 2 deletions examples/with-typescript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
"type": "module",
"scripts": {
"bench-benchmark-js": "node --loader esbuild-register/loader -r esbuild-register bench/benchmark.js/index.bench.ts",
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register bench/tinybench/index.bench.ts"
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register bench/tinybench/index.bench.ts",
"bench-vitest": "vitest bench"
},
"devDependencies": {
"@codspeed/benchmark.js-plugin": "workspace:*",
"@codspeed/tinybench-plugin": "workspace:*",
"@codspeed/vitest-plugin": "workspace:*",
"@types/benchmark": "^2.1.2",
"benchmark": "^2.1.4",
"esbuild-register": "^3.4.2",
"tinybench": "^2.5.0",
"typescript": "^5.1.3"
"typescript": "^5.1.3",
"vitest": "1.0.0-beta.4"
}
}
8 changes: 8 additions & 0 deletions examples/with-typescript-esm/src/fibonacci.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { bench, describe } from "vitest";
import { iterativeFibonacci } from "./fibonacci";

describe("iterativeFibonacci", () => {
bench("fibo 10", () => {
iterativeFibonacci(10);
});
});
8 changes: 8 additions & 0 deletions examples/with-typescript-esm/src/fibonacci.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from "vitest";
import { iterativeFibonacci } from "./fibonacci";

describe("iterativeFibonacci", () => {
it("should return the correct value", () => {
expect(iterativeFibonacci(1)).toBe(1);
});
});
28 changes: 0 additions & 28 deletions examples/with-typescript-esm/src/foobarbaz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,3 @@ function bar(n: number) {
export function baz(n: number) {
bar(n);
}

// Async version
function dummyThingToAwait() {
return new Promise<void>((resolve) => {
process.nextTick(() => {
resolve();
});
});
}

async function aFoo(n: number) {
await dummyThingToAwait();
let result = 0;
for (let i = 0; i < n; i++) {
result += 1;
}
return result;
}

async function aBar(n: number) {
await dummyThingToAwait();
await aFoo(n);
}

export async function aBaz(n: number) {
await dummyThingToAwait();
await aBar(n);
}
11 changes: 11 additions & 0 deletions examples/with-typescript-esm/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import codspeedPlugin from "@codspeed/vitest-plugin";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [codspeedPlugin()],
test: {
benchmark: {
exclude: ["**/bench/**/*", "**/node_modules/**/*"],
},
},
});
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"devDependencies": {
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@moonrepo/cli": "^1.9.2",
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@moonrepo/cli": "^1.15.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.58.0",
Expand All @@ -24,9 +24,9 @@
"lerna": "^6.6.1",
"prettier": "^2.8.7",
"prettier-plugin-organize-imports": "^3.2.2",
"rollup": "^3.20.2",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup": "^4.4.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.0",
"ts-jest": "^29.1.0",
"tslib": "^2.5.0",
"typescript": "4.9.4"
Expand Down
1 change: 1 addition & 0 deletions packages/benchmark.js-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Benchmark.js compatibility layer for CodSpeed
[![CI](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml)
[![npm (scoped)](https://img.shields.io/npm/v/@codspeed/benchmark.js-plugin)](https://www.npmjs.com/package/@codspeed/benchmark.js-plugin)
[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/codspeed-node)

</div>

Expand Down
Loading