Skip to content

Commit ccf65cf

Browse files
mfrachetMastra Code (anthropic/claude-opus-4-6)
andcommitted
feat: add evaluateAll benchmark with tinybench
- Add tinybench devDependency and 'bench' script - Create 20-flag config exercising all operator types, segments, variants, and disabled flags (3 true, 6 false, 11 variant results) - Benchmark runner for evaluateAll: ~418K ops/s (~2.6μs per call) Run with: npm run bench (from packages/core) Co-Authored-By: Mastra Code (anthropic/claude-opus-4-6) <noreply@mastra.ai>
1 parent 0c0202a commit ccf65cf

File tree

4 files changed

+525
-0
lines changed

4 files changed

+525
-0
lines changed

packages/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"test": "vitest",
2121
"coverage": "vitest run --coverage",
2222
"lint": "eslint .",
23+
"bench": "tsx src/__benchmarks__/evaluateAll.bench.ts",
2324
"bundlesize": "bundlesize"
2425
},
2526
"keywords": [],
@@ -36,6 +37,7 @@
3637
"bundlesize": "^0.18.2",
3738
"eslint": "^9.29.0",
3839
"rollup": "^4.44.0",
40+
"tinybench": "^6.0.0",
3941
"tslib": "^2.8.1",
4042
"tsx": "^4.20.3",
4143
"typescript": "^5.8.3",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Bench } from "tinybench";
2+
import { createFlagEngine } from "../index";
3+
import { benchmarkFlags } from "./flagsConfig";
4+
5+
const bench = new Bench({ warmupIterations: 100 });
6+
7+
const engine = createFlagEngine(benchmarkFlags);
8+
9+
// User context that exercises every operator type in the config
10+
const userCtx = engine.createUserContext({
11+
__id: "bench-user-42",
12+
plan: "premium",
13+
country: "FR",
14+
email: "bench@company.com",
15+
age: 28,
16+
status: "active",
17+
totalOrders: 150,
18+
lifetimeValue: 1200,
19+
browser: "Chrome",
20+
role: "admin",
21+
accountAgeDays: 400,
22+
onboardingComplete: true,
23+
language: "fr",
24+
});
25+
26+
bench.add("evaluateAll (20 flags)", () => {
27+
userCtx.evaluateAll();
28+
});
29+
30+
await bench.run();
31+
console.table(bench.table());

0 commit comments

Comments
 (0)