Benchmarking System
Relevant source files
The following files were used as context for generating this wiki page:- packages/benchmarks/README.md
- packages/benchmarks/test-cases.ts
- packages/website/app/blog/intro/page.tsx
- packages/website/components/benchmarks/benchmark-detailed-table.tsx
- packages/website/components/benchmarks/benchmark-charts.tsx
- packages/benchmarks/index.html
- packages/benchmarks/package.json
- CONTRIBUTING.md
The react-grab project includes a dedicated benchmarking system to quantitatively measure the impact of the tool on the performance of AI coding agents. The system is designed to provide empirical evidence of the speed and efficiency gains achieved by providing agents with precise component context, as opposed to relying on traditional codebase search methods.
The benchmark suite executes a series of real-world UI editing tasks on a sample application, comparing a "control" group (agent without react-grab) against a "treatment" group (agent with react-grab). It collects detailed metrics on performance, cost, and accuracy, which are then used to generate reports and visualizations. The results consistently show that react-grab makes coding agents approximately 3x faster on average.
Sources: packages/benchmarks/README.md, packages/website/app/blog/intro/page.tsx:320-326
Architecture and Methodology
The benchmark's methodology is centered around a controlled experiment. It uses the shadcn/ui dashboard as a consistent testbed, which is a production-grade Next.js application. Each test case is run twice to create the two comparison groups.
Sources: packages/benchmarks/README.md:5-6, packages/website/app/blog/intro/page.tsx:300-306
- Control Group: The coding agent is given a natural language prompt and must search the codebase to find the relevant UI element.
- Treatment Group: The agent receives the same prompt augmented with the contextual output from
react-grab, which includes the component stack with exact file paths and line numbers.
The following diagram illustrates the workflow for a single test run within the benchmark suite.
This flowchart shows the parallel execution paths for the control and treatment groups for each test case. Sources: packages/benchmarks/README.md:8-11
Measured Metrics
The system captures several key metrics to evaluate performance from different angles.
| Metric | Description |
|---|---|
durationMs | The total time taken to complete the task, in milliseconds. |
toolCalls | The number of tool calls (e.g., file reads, searches) the agent made. |
inputTokens | The number of tokens in the prompt sent to the model. |
outputTokens | The number of tokens generated by the model in its response. |
totalTokens | The sum of input and output tokens. |
costUsd | The estimated API cost for the test run in USD. |
success | A boolean indicating whether the agent successfully identified the correct file. |
Sources: packages/benchmarks/README.md:13-20, packages/website/components/benchmarks/benchmark-detailed-table.tsx:298-319
Test Cases
The benchmark consists of 20 predefined test cases that represent common, real-world UI editing scenarios. These tasks cover a wide range of components, from simple buttons and links to more complex elements within data tables, forms, and navigation menus.
Sources: packages/benchmarks/README.md:46-52, packages/benchmarks/test-cases.ts:5-7
Data Structure
Each test case is defined by the TestCase interface, which includes the prompt for the agent and the context needed to validate the test.
This class diagram shows the structure of a single test case object. Sources: packages/benchmarks/test-cases.ts:1-6
Example Test Cases
The following table shows a few examples from the full suite of test cases.
| Test Name | Prompt | Expected File |
|---|---|---|
| Grayscale Avatar | Find the grayscale avatar in the user menu | components/nav-user.tsx |
| Forgot Password Link | Find the forgot password link in the login form | components/login-form.tsx |
| Drag Handle | Find the drag handle with grip vertical icon in the table rows | components/data-table.tsx |
| OTP Input | Find the OTP input with separator showing 6-digit verification code | components/otp-form.tsx |
| Revenue Card Badge | Find the trending up badge showing +12.5% in the Total Revenue card | components/section-cards.tsx |
Sources: packages/benchmarks/test-cases.ts:8-40
Execution and Configuration
The benchmark suite is executed via a script and requires a specific environment setup.
Prerequisites
- Node.js >= 18
- pnpm >= 8
- An Anthropic API key with access to Claude Code, set as the
ANTHROPIC_API_KEYenvironment variable.
Sources: packages/benchmarks/README.md:22-34
Running the Benchmark
The benchmark is initiated by running bun index.ts from the packages/benchmarks directory. The script will generate test-cases.json, run all 40 tests (20 control + 20 treatment), and save the results to results.json.
Sources: packages/benchmarks/README.md:36-44
Customization
The benchmark can be customized by modifying the source files:
| Parameter | File to Edit | Description |
|---|---|---|
| Test Cases | test-cases.ts | Add, remove, or modify test scenarios. |
| Batch Size | index.ts | Change BATCH_SIZE to control concurrent tests. |
| Test Codebase | index.ts | Update TARGET_ENVIRONMENT_DIR to point to a different project. |
| AI Model | claude-code.ts | Modify the model used for the tests (e.g., claudeCode("sonnet")). |
Sources: packages/benchmarks/README.md:61-66
Results and Visualization
Benchmark results are persisted in results.json and visualized through both a static HTML page and dynamic React components on the project's website.
Result Data Structure
Each entry in the results.json file corresponds to a single test run (either control or treatment) and follows the BenchmarkResult structure.
{
"testName": "Forgot Password Link",
"type": "control",
"inputTokens": 12345,
"outputTokens": 234,
"totalTokens": 12579,
"costUsd": 0.012,
"durationMs": 13600,
"toolCalls": 5,
"success": true
}
Sources: packages/benchmarks/README.md:48-58
Visualization Components
The website uses several React components to display the benchmark data in an interactive and understandable format.
BenchmarkCharts: Renders bar charts comparing aggregated metrics (Avg Duration, Total Cost, Avg Tool Calls) between the control and treatment groups. It normalizes the control group to 100% for easy comparison.BenchmarkDetailedTable: Displays a detailed, sortable, and filterable table of results for every test case, showing the raw numbers and percentage change for each metric.TimeComparisonChart: A specialized area chart showing the distribution of edit times for both groups, highlighting the average time and speedup factor.
The following diagram shows the data flow from the raw results to the UI.
This diagram illustrates how the results.json file is consumed by both the dynamic React components on the website and the static index.html report. Sources: packages/website/app/blog/intro/page.tsx:18-43, packages/benchmarks/index.html:128-135, packages/website/components/benchmarks/benchmark-charts.tsx, packages/website/components/benchmarks/benchmark-detailed-table.tsx
Conclusion
The benchmarking system is a critical component of the react-grab project, providing robust, data-driven validation of the tool's core value proposition. By systematically comparing agent performance with and without the react-grab context, the benchmarks demonstrate a significant reduction in task completion time, API costs, and agent search complexity. These results are foundational to the project's claim of making UI development with AI agents faster and more efficient.
Sources: packages/benchmarks/README.md:83-84, packages/website/app/blog/intro/page.tsx:320-326