200-600x slower Dlang performance with nested foreach loop

Paul Backus snarwin at gmail.com
Tue Jan 26 17:56:22 UTC 2021


On Tuesday, 26 January 2021 at 17:40:36 UTC, methonash wrote:
> foreach( i, ref pStr; sortedArr )
> {
>     foreach( j, ref cStr; sortedArr[ i + 1 .. $ ] )
>     {
>         if( indexOf( pStr, cStr ) > -1 )
>         {
>             // ...
>         }
>     }
> }
>
> Before adding the code excerpt above, the Dlang program was 
> taking ~1 second on an input file containing approx. 64,000 
> strings.
>
> By adding the code above, the program now takes 6 minutes to 
> complete.

It would be much easier for us to help you with this if you could 
post the full program, or at the very least a reduced version 
that reproduces the same issue. [1] Since your attempts so far 
have failed to fix the problem, it is quite likely that some part 
of the code you do not suspect is actually to blame.

[1] https://idownvotedbecau.se/nomcve/


More information about the Digitalmars-d-learn mailing list