foreach (i; taskPool.parallel(0..2_000_000)
H. S. Teoh
hsteoh at qfbox.info
Tue Apr 4 22:20:52 UTC 2023
On Tue, Apr 04, 2023 at 09:35:29PM +0000, Paul via Digitalmars-d-learn wrote:
[...]
> Well Steven just making the change you said reduced the execution time
> from ~6-7 secs to ~3 secs. Then, including the 'parallel' in the
> foreach statement took it down to ~1 sec.
>
> Boy lesson learned in appending-to and zeroing dynamic arrays in a hot
> loop!
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).
T
--
Famous last words: I *think* this will work...
More information about the Digitalmars-d-learn
mailing list