Skip to content

Commit

Permalink
Restore plugin and add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed May 7, 2024
1 parent ea5d470 commit 00db7b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/nodes-base/benchmark.env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const NodeEnvironment = require('jest-environment-node').TestEnvironment;
const { Bench } = require('tinybench');
const { withCodSpeed } = require('@codspeed/tinybench-plugin');

class BenchmarkEnvironment extends NodeEnvironment {
constructor(config, context) {
Expand All @@ -10,10 +11,12 @@ class BenchmarkEnvironment extends NodeEnvironment {
}

async setup() {
console.log('[benchmarking] env setup');
await super.setup();
}

async teardown() {
console.log('[benchmarking] env teardown');
await this.benchmark();

await super.teardown();
Expand All @@ -24,16 +27,20 @@ class BenchmarkEnvironment extends NodeEnvironment {
}

setupBenchmark() {
this.bench = new Bench();
console.log('[benchmarking] this.bench setup');
this.bench = withCodSpeed(new Bench());
}

async benchmark() {
console.log('[benchmarking] bench warmup');
await this.bench.warmup();
console.log('[benchmarking] bench run');
await this.bench.run();
}

async handleTestEvent(event) {
if (event.name === 'add_test') {
console.log('[benchmarking] add test', event.testName);
this.bench.add(event.testName, event.fn);
}
}
Expand Down

0 comments on commit 00db7b6

Please sign in to comment.