"foreach(i, dchar c; s)" vs "decode"

Jonathan M Davis jmdavisProg at gmx.com
Sun Nov 25 13:50:53 PST 2012


On Sunday, November 25, 2012 22:37:24 monarch_dodra wrote:
> I got these results on 2.061 alpha release, with phobos in
> release and both -inline and without inline.

You should also be testing with -O if you're benchmarking, but I still would 
have thought that the compiler would be faster. Apparently not. I believe that 
definite work has been put into improving the decode, stride, popFront, etc. in 
Phobos over the past year or two, so they've definitely been improving. I 
suspect that whatever the compiler is doing hasn't been touched in ages, and I 
have no idea what improvements could or couldn't be done. It _is_ the sort of 
thing that I'd kind of expect to be sitting somewhere in druntime though. If 
it is, maybe foreach and Phobos' implemenations can be made to share in some 
way. I don't know (though IMHO speed should be more important here than 
reducing code duplication).

The speed of foreach's decoding definitely matters, but in the code that I've 
really been trying to make fast, I don't generally use it, because it's often 
the case that some portion of what I'm doing can be made faster by skipping 
decoding for some portion of the characters (like explicitly handling the code 
units for paraSep and lineSep in code that cares about the end of lines). 
Making string processing fast should definitely be one of our performance 
priorities though IMHO given how big an impact that can have on many programs 
and how unfriendly ranges generally are to efficient string processing.

- Jonathan M Davis


More information about the Digitalmars-d mailing list