// For each pixel, average all neighbors within radius
// O(n * k²) where n = pixels, k = blur radius
Each pixel reads k² neighbors. The nested loops make this quadratic in the blur radius.
| Image Size | Naive Blur | Status |
|---|---|---|
| 100×100 | 12ms | ✅ Fine |
| 500×500 | 280ms | ⚠ Noticeable |
| 1000×1000 | 1100ms | 🔴 Slow |
| 3840×2160 | 15000ms | 🔴 Unacceptable! |
Two-pass approach: horizontal blur first, then vertical blur on the result.
| Image Size | Separable Blur | Speedup |
|---|---|---|
| 100×100 | 3ms | 4× |
| 500×500 | 35ms | 8× |
| 1000×1000 | 120ms | 9× |
| 3840×2160 | 800ms | 19× |
Plot the benchmark results: image size on X axis, time on Y axis. See the O(n × k²) curve shoot upward while O(n × 2k) stays nearly flat.
| Big O | Name | PixelCraft Example |
|---|---|---|
| O(1) | Constant | pixels[500] — instant regardless of size |
| O(n) | Linear | Grayscale — visits each pixel once |
| O(n log n) | Linearithmic | Sorting the gallery by name |
| O(n²) | Quadratic | Naive blur — nested loops |
| O(2ⁿ) | Exponential | Brute-force password cracking |
git switch -c perf/PIXELCRAFT-021-optimize-blur
git add src/scripts/
git commit -m "Optimize blur with separable algorithm, 15x faster (PIXELCRAFT-021)"
git push origin perf/PIXELCRAFT-021-optimize-blur
# PR → Review → Merge → Close ticket ✅
Algorithm analysis is the heart of CS.
For 8 million pixels: