Modified permuteExistingNumbers() to pre-allocate sufficiently large slice for all results.
Based on profiling, significant time was spent in growSlice() and memMove() as
a result of the per-number slice append(). Consolidating the allocations resulted
in significant speed and memory usage improvements.
Benchmarking command:
time ./ch1-breeding-numbers -generations 13 -silent
go tool pprof ch1-breeding-numbers 13gen-memprofile-gen12.mprof
top25
Before:
71.978u 3.726s 0:31.79 238.0% 0+0k 40+75io 353pf+0w
Showing nodes accounting for 3.70GB, 100% of 3.70GB total
After:
38.303u 2.233s 0:23.41 173.1% 0+0k 40+62io 354pf+0w
Showing nodes accounting for 2.29GB, 100% of 2.29GB total