Why is for() less efficient than foreach?

evilrat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 10 05:26:11 PST 2017


On Friday, 10 February 2017 at 13:13:24 UTC, evilrat wrote:
>
> On my machine (AMD FX-8350) actually almost no difference


oops, it skips flags with -run -_-
sorry

dmd loops.d -release
Function 0 took: 16 ╬╝s and 5 hnsecs
Function 1 took: 55 secs, 262 ms, 844 ╬╝s, and 6 hnsecs
Function 2 took: 56 secs, 564 ms, 231 ╬╝s, and 6 hnsecs

ldc2 loops.d -release
Function 0 took: 25 ╬╝s and 5 hnsecs
Function 1 took: 46 secs, 757 ms, 889 ╬╝s, and 7 hnsecs
Function 2 took: 23 secs, 895 ms, 410 ╬╝s, and 3 hnsecs

dmd loops.d -m64 -release
Function 0 took: 24 ╬╝s and 7 hnsecs
Function 1 took: 27 secs, 752 ms, 952 ╬╝s, and 5 hnsecs
Function 2 took: 36 secs, 550 ms, 295 ╬╝s, and 4 hnsecs

ldc2 loops.d -m64 -release
Function 0 took: 25 ╬╝s
Function 1 took: 47 secs, 456 ms, 65 ╬╝s, and 4 hnsecs
Function 2 took: 26 secs, 583 ms, 880 ╬╝s, and 1 hnsec

setting LDC with any optimization flags completely removes empty 
call and for loop.


More information about the Digitalmars-d-learn mailing list