You are a senior Go engineer.
Implement a high-performance Go program that calculates the Mandelbrot set and renders it as a PNG image.
Requirements:
- Use pure Go standard library only.
- Support configurable image size, max iterations, and output filename via CLI flags.
- Parallelize computation using goroutines and worker pools.
- Optimize memory allocations and avoid unnecessary copying.
- Generate a grayscale PNG output.
- Add benchmarks for the core computation.
- Add unit tests for escape-time calculations.
- Organize code cleanly with:
- cmd/
- internal/
- pkg/
- Include a README explaining:
- architecture
- concurrency model
- optimization decisions
- how to run benchmarks
Extra challenge:
- Add SIMD-like optimization ideas in comments.
- Compare static vs dynamic worker scheduling.
- Print total render time and pixels/sec.
The code should be production-quality and compile with: go build ./...
Then explain:
- Time complexity
- Memory behavior
- Concurrency tradeoffs
- Possible GPU offloading approaches