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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chainsafe/benchmark",
"version": "1.1.0-rc.4",
"version": "1.1.0-rc.5",
"repository": "git@github.com:chainsafe/benchmark.git",
"author": "ChainSafe Systems",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class BenchmarkReporter {

const ratio = result.averageNs / prevResult.averageNs;
if (ratio > threshold) {
const fmt = this.indent() + color("fail", " " + symbols.err) + " " + resultRow;
const fmt = this.indent() + color("fail", " " + symbols.bang) + " " + resultRow;
consoleLog(fmt);
this.failed++;
return;
Expand Down
8 changes: 8 additions & 0 deletions src/benchmark/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {BenchmarkReporter} from "./reporter.js";
import {store} from "./globalState.js";

export class BenchmarkRunner implements VitestRunner {
readonly triggerGC: boolean;
readonly config: VitestRunnerConfig;
readonly reporter: BenchmarkReporter;
readonly prevBench: Benchmark | null;
Expand All @@ -29,6 +30,7 @@ export class BenchmarkRunner implements VitestRunner {
setupFiles: benchmarkOpts.setupFiles ? benchmarkOpts.setupFiles.map((s) => path.resolve(s)) : [],
retry: 0,
};
this.triggerGC = benchmarkOpts.triggerGC ?? false;
this.prevBench = prevBench;
this.benchmarkOpts = benchmarkOpts;
this.reporter = new BenchmarkReporter({prevBench, benchmarkOpts});
Expand All @@ -50,6 +52,12 @@ export class BenchmarkRunner implements VitestRunner {
onAfterRunTask(task: Task): void {
this.reporter.onTestFinished(task);
store.removeOptions(task);

// To help maintain consistent memory usage patterns
// we trigger garbage collection manually
if (this.triggerGC && global.gc) {
global.gc();
}
}

onAfterRunFiles(files: File[]): void {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,10 @@ export const benchmarkOptions: ICliCommandOptions<CLIBenchmarkOptions> = {
default: [],
group: benchmarkGroup,
},
triggerGC: {
type: "boolean",
description: "Trigger GC (if available) after every benchmark",
default: false,
group: benchmarkGroup,
},
};
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export type BenchmarkOpts = {
skip?: boolean;
/** Setup files to load before the test files */
setupFiles?: string[];
/** Trigger GC cleanup every test to have consistent memory usage */
triggerGC?: boolean;
};

// Create partial only for specific keys
Expand Down