Help optimizing code?
Adam D. Ruppe
destructionator at gmail.com
Mon Jan 1 16:47:40 UTC 2018
On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote:
> If you use .ptr then you get zero detection, even in debug
> builds.
It is limited to the one expression where you wrote it, instead
of on the ENTIRE program like the build switches do.
It is a lot easier to check correctness in an individual
expression than it is to check the entire program, including
stuff you didn't even realize might have been a problem.
With the .ptr pattern, it is correct by default and you
individually change ones you (should) look carefully at. With
-boundscheck, it is wrong by default and most people don't even
look at it - people suggest it to newbies as an optimization
without mentioning how nasty it is.
> I'd rather there be a potential bug than the program running to
> slow to be usable
That's a ridiculous exaggeration. In this program, I saw a < 1%
time difference using those flags. -O -inline make a 50x bigger
difference!
> or have zero debugging for indices in debug builds.
You shouldn't be using .ptr until after you've carefully checked
and debugged the line of code where you are writing it. That's
the beauty of the pattern: it only affects one line of code, so
you can test it before you use it without affecting the rest of
the program.
More information about the Digitalmars-d-learn
mailing list