foreach (i; taskPool.parallel(0..2_000_000)

Paul phshaffer at gmail.com
Wed Apr 5 22:34:22 UTC 2023


On Tuesday, 4 April 2023 at 22:20:52 UTC, H. S. Teoh wrote:

> Best practices for arrays in hot loops:
> - Avoid appending if possible; instead, pre-allocate outside 
> the loop.
> - Where possible, reuse existing arrays instead of discarding 
> old ones
>   and allocating new ones.
> - Use slices where possible instead of making copies of 
> subarrays (this
>   esp. applies to strings).
> - Where possible, prefer sequential access over random access 
> (take
>   advantage of the CPU cache hierarchy).

Thanks for sharing Teoh!  Very helpful.

would this be random access? for(size_t i; i<arr.length; i++) 
using indices?
...and this be sequential foreach(a;arr) ?

or would they have to be completely different kinds of containers?
a dlang 'range' vs arr[]?




More information about the Digitalmars-d-learn mailing list