Benchmarking
Tools and techniques for measuring and optimizing gas consumption in CoW Protocol smart contracts.
Benchmark Commands
Full Suite
Execute the complete benchmark suite across settlement scenarios:
Execution Tracing
Generate detailed execution traces identifying gas consumption patterns:
Tracing reveals:
- Call stack hierarchy
- Per-operation gas consumption
- Storage operations
- External calls
- Event emission expenses
Version Comparison
Compare performance between code versions:
The comparison script performs five steps:
- Stash current changes
- Benchmark current code
- Check out reference commit
- Benchmark reference code
- Generate differential report
Interpreting results:
- Positive values indicate regressions (increased gas)
- Negative values show improvements (decreased gas)
Single Scenario
Test individual settlement scenarios:
Optimization Strategy
Follow a structured five-phase approach:
- Establish baseline - Measure current gas consumption
- Identify hotspots - Use tracing to find expensive operations
- Implement improvements - Target specific gas-heavy operations
- Verify gains - Compare against baseline measurements
- Comprehensive testing - Ensure correctness is maintained
Compiler Configuration
The project compiler prioritizes execution costs:
| Setting | Value | Rationale |
|---|
| Optimizer | Enabled | Gas efficiency |
| Optimizer Runs | 1,000,000 | Favor execution over deployment |
| EVM Version | Cancun | Latest EVM features |
Best Practices
- Ensure clean builds without coverage instrumentation before benchmarking
- Use a stable environment (same machine, similar load)
- Run multiple iterations for consistent results
- Compare against known reference points
- Document significant performance changes
Coverage instrumentation alters contract bytecode and gas costs. Always benchmark against clean, non-instrumented builds.