--- description: Benchmark and optimize code argument-hint: "" --- # Benchmark and optimize code **Target**: $ARGUMENTS Workflow: 1. **Profile** - Use profiling to find hotspots and other performance problems Prefer canonical profiling tools for system at hand, otherwise fall back to tracing and wall time. 2. **Baseline** - Create benchmark 3. **Analyze** - Check code 4. **Optimize** - Write efficient code 5. **Verify** - Re-run benchmark, compare with benchstat 6. **Document** - Comment optimization rationale To make sure old behaviour did not break, run tests. If code to be optimized is not tested, write tests first. If changes are needed to system tools, dependencies or build system, report to human.