Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.54 KB

File metadata and controls

50 lines (36 loc) · 1.54 KB

Benchmark Results

Benchmarking solve.go with bg-1.png and slice-1.png.

Environment

  • CPU: Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  • OS: Windows 10
  • Go: go1.25.0

Results

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

CPU Profile Analysis

Function Time Percentage
calculateMaskedNCC 8.87s 38.58%
GrayAt 3.46s 15.05%
AlphaAt 2.72s 11.83%
FindBestMatchMasked 1.01s 4.39%

Running the Benchmark

# 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

Key Bottlenecks

  1. Template matching loop - calculateMaskedNCC() consumes 38.6% of CPU time
  2. Pixel access overhead - Individual GrayAt()/AlphaAt() calls account for ~27%
  3. Bounds checking - image.Point.In takes 11.7%

Optimization Opportunities

  1. Replace GrayAt()/AlphaAt() with direct slice access to the underlying pixel buffer
  2. Add threshold-based early exit in NCC calculation
  3. Use goroutines for parallel search positions
  4. Pre-compute mean values to avoid repeated sums