https://issues.dlang.org/show_bug.cgi?id=18629
--- Comment #2 from John Colvin <john.loughran.col...@gmail.com> --- If you compile with LDC and full optimisations (substitute isn't in LDC's phobos, see attached file for a working example) then the disparity goes away (without bounds checking v3 is even faster). This is normal for range-based code, dmd isn't good at optimising it. Except that's not the end of the story. If you append extra nonsense to the end of the input string (-version=LongerString in the attached file)then the substitute version gets a lot slower again, so perhaps substitute really is doing something slow and stupid. --