Benchmarking solve.go with bg-1.png and slice-1.png.
- CPU: Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
- OS: Windows 10
- Go: go1.25.0
| Test | Time | Memory | Allocations |
|---|---|---|---|
| BenchmarkSolve | 1,005,133,900 ns/op (~1.0s) | 4,740,528 B/op | 313 allocs/op |
| BenchmarkSolveWithTime | 1,148,064,800 ns/op (~1.1s) | 4,723,152 B/op | 286 allocs/op |
| Function | Time | Percentage |
|---|---|---|
| calculateMaskedNCC | 8.87s | 38.58% |
| GrayAt | 3.46s | 15.05% |
| AlphaAt | 2.72s | 11.83% |
| FindBestMatchMasked | 1.01s | 4.39% |
# Run benchmark
go test -bench=. -benchmem ./...
# Run with CPU profile
go test -bench=BenchmarkSolve -cpuprofile=cpu.out -benchtime=5s -run=^$
# View CPU profile
go tool pprof cpu.out- Template matching loop - calculateMaskedNCC() consumes 38.6% of CPU time
- Pixel access overhead - Individual GrayAt()/AlphaAt() calls account for ~27%
- Bounds checking - image.Point.In takes 11.7%