4 ms·
For one thing, that will use much more memory and take more time to compute.
by yoklov 13y ago
For one thing, that will use much more memory and take more time to compute.
- JulianMorrison 13y agoDon't underestimate the time cost of coroutining (literally goroutining, and using a channel, or to-and-fro with HasNext and Next). And the unfinished generator is using memory, too. Code runs fastest when it can sit in cache, so creating a slice in a tight loop and returning it is probably optimal if the actual data you just materialized is small.
- yoklov 13y agoSure, it's better than the goroutine approach, but that doesn't say much. It becomes quite suboptimal if you have a large amount of data. I also think that you're likely underestimating the cost of the additional memory allocations.