Skip to content

Commit 5ee0428

Browse files
feat: rename instrumentation to simulation
`instrumentation` is still accepted as an input, but it maps to simulation internally, as we plan to phase it out.
1 parent 174369c commit 5ee0428

File tree

12 files changed

+44
-34
lines changed

12 files changed

+44
-34
lines changed

packages/core/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const isBound = native_core.isBound;
1010

1111
export const mongoMeasurement = new MongoMeasurement();
1212

13-
type CodSpeedRunnerMode = "disabled" | "instrumented" | "walltime";
13+
type CodSpeedRunnerMode = "disabled" | "simulation" | "walltime";
1414

1515
export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
1616
const isCodSpeedEnabled = process.env.CODSPEED_ENV !== undefined;
@@ -20,8 +20,8 @@ export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
2020

2121
// If CODSPEED_ENV is set, check CODSPEED_RUNNER_MODE
2222
const codspeedRunnerMode = process.env.CODSPEED_RUNNER_MODE;
23-
if (codspeedRunnerMode === "instrumentation") {
24-
return "instrumented";
23+
if (codspeedRunnerMode === "instrumentation" || codspeedRunnerMode === "simulation") {
24+
return "simulation";
2525
} else if (codspeedRunnerMode === "walltime") {
2626
return "walltime";
2727
}

packages/core/src/introspection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getV8Flags = () => {
99

1010
const flags = ["--interpreted-frames-native-stack", "--allow-natives-syntax"];
1111

12-
if (codspeedRunnerMode === "instrumented") {
12+
if (codspeedRunnerMode === "simulation") {
1313
flags.push(
1414
...[
1515
"--hash-seed=1",

packages/tinybench-plugin/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import path from "path";
1111
import { get as getStackTrace } from "stack-trace";
1212
import { Bench } from "tinybench";
1313
import { fileURLToPath } from "url";
14-
import { setupCodspeedInstrumentedBench } from "./instrumented";
14+
import { setupCodspeedSimulationBench } from "./simulation";
1515
import { getOrCreateUriMap } from "./uri";
1616
import { setupCodspeedWalltimeBench } from "./walltime";
1717

@@ -39,8 +39,8 @@ export function withCodSpeed(bench: Bench): Bench {
3939
return rawAdd.bind(bench)(name, fn, opts);
4040
};
4141

42-
if (codspeedRunnerMode === "instrumented") {
43-
setupCodspeedInstrumentedBench(bench, rootCallingFile);
42+
if (codspeedRunnerMode === "simulation") {
43+
setupCodspeedSimulationBench(bench, rootCallingFile);
4444
} else if (codspeedRunnerMode === "walltime") {
4545
setupCodspeedWalltimeBench(bench, rootCallingFile);
4646
}

packages/tinybench-plugin/src/index.unit.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Bench } from "tinybench";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
33
import { withCodSpeed } from ".";
44

5-
const mockInstrumented = vi.hoisted(() => ({
6-
setupCodspeedInstrumentedBench: vi.fn(),
5+
const mockSimulation = vi.hoisted(() => ({
6+
setupCodspeedSimulationBench: vi.fn(),
77
}));
88

9-
vi.mock("./instrumented", () => ({
10-
...mockInstrumented,
9+
vi.mock("./simulation", () => ({
10+
...mockSimulation,
1111
}));
1212

1313
const mockWalltime = vi.hoisted(() => ({
@@ -38,13 +38,23 @@ describe("withCodSpeed behavior without different codspeed modes", () => {
3838
expect(shouldBeCalled.mock.calls.length).toBeGreaterThan(1000);
3939
});
4040

41-
it("should run in instrumented mode when CODSPEED_RUNNER_MODE=instrumentation", async () => {
41+
it("should run in simulation mode when CODSPEED_RUNNER_MODE=instrumentation", async () => {
4242
process.env.CODSPEED_ENV = "true";
4343
process.env.CODSPEED_RUNNER_MODE = "instrumentation";
4444

4545
withCodSpeed(new Bench());
4646

47-
expect(mockInstrumented.setupCodspeedInstrumentedBench).toHaveBeenCalled();
47+
expect(mockSimulation.setupCodspeedSimulationBench).toHaveBeenCalled();
48+
expect(mockWalltime.setupCodspeedWalltimeBench).not.toHaveBeenCalled();
49+
});
50+
51+
it("should run in simulation mode when CODSPEED_RUNNER_MODE=simulation", async () => {
52+
process.env.CODSPEED_ENV = "true";
53+
process.env.CODSPEED_RUNNER_MODE = "simulation";
54+
55+
withCodSpeed(new Bench());
56+
57+
expect(mockSimulation.setupCodspeedSimulationBench).toHaveBeenCalled();
4858
expect(mockWalltime.setupCodspeedWalltimeBench).not.toHaveBeenCalled();
4959
});
5060

@@ -55,7 +65,7 @@ describe("withCodSpeed behavior without different codspeed modes", () => {
5565
withCodSpeed(new Bench());
5666

5767
expect(
58-
mockInstrumented.setupCodspeedInstrumentedBench
68+
mockSimulation.setupCodspeedSimulationBench
5969
).not.toHaveBeenCalled();
6070
expect(mockWalltime.setupCodspeedWalltimeBench).toHaveBeenCalled();
6171
});

packages/tinybench-plugin/src/instrumented.ts renamed to packages/tinybench-plugin/src/simulation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import {
66
import { Bench, Fn, FnOptions, Task } from "tinybench";
77
import { BaseBenchRunner } from "./shared";
88

9-
export function setupCodspeedInstrumentedBench(
9+
export function setupCodspeedSimulationBench(
1010
bench: Bench,
1111
rootCallingFile: string
1212
): void {
13-
const runner = new InstrumentedBenchRunner(bench, rootCallingFile);
13+
const runner = new SimulationBenchRunner(bench, rootCallingFile);
1414
runner.setupBenchMethods();
1515
}
1616

17-
class InstrumentedBenchRunner extends BaseBenchRunner {
17+
class SimulationBenchRunner extends BaseBenchRunner {
1818
protected getModeName(): string {
19-
return "instrumented mode";
19+
return "simulation mode";
2020
}
2121

2222
private taskCompletionMessage() {

packages/tinybench-plugin/tests/__snapshots__/index.integ.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`Benchmark.Suite > check console output(instrumented=%p) false 1`] = `
44
{
55
"log": [
66
[
7-
"[CodSpeed] running with @codspeed/tinybench v1.0.0 (instrumented mode)",
7+
"[CodSpeed] running with @codspeed/tinybench v1.0.0 (simulation mode)",
88
],
99
[
1010
"[CodSpeed] Checked packages/tinybench-plugin/tests/index.integ.test.ts::RegExp",

packages/vitest-plugin/rollup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default defineConfig([
2121
external: ["@codspeed/core", /^vitest/],
2222
},
2323
{
24-
input: "src/instrumented.ts",
25-
output: { file: "dist/instrumented.mjs", format: "es" },
24+
input: "src/simulation.ts",
25+
output: { file: "dist/simulation.mjs", format: "es" },
2626
plugins: jsPlugins(pkg.version),
2727
external: ["@codspeed/core", /^vitest/],
2828
},

packages/vitest-plugin/src/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("codSpeedPlugin", () => {
107107
},
108108
},
109109
runner: expect.stringContaining(
110-
"packages/vitest-plugin/src/instrumented.ts"
110+
"packages/vitest-plugin/src/simulation.ts"
111111
),
112112
},
113113
});

packages/vitest-plugin/src/__tests__/instrumented.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromPartial } from "@total-typescript/shoehorn";
22
import { describe, expect, it, vi, type RunnerTestSuite } from "vitest";
33
import { getBenchFn } from "vitest/suite";
4-
import { InstrumentedRunner as CodSpeedRunner } from "../instrumented";
4+
import { SimulationRunner as CodSpeedRunner } from "../simulation";
55

66
const coreMocks = vi.hoisted(() => {
77
return {

packages/vitest-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function codspeedPlugin(): Plugin {
3737
return false;
3838
}
3939
if (
40-
getCodspeedRunnerMode() == "instrumented" &&
40+
getCodspeedRunnerMode() == "simulation" &&
4141
!InstrumentHooks.isInstrumented()
4242
) {
4343
console.warn("[CodSpeed] bench detected but no instrumentation found");

0 commit comments

Comments
 (0)