Trust about D programming.

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 24 08:43:55 PST 2013


On Thu, Jan 24, 2013 at 05:34:52PM +0100, Paulo Pinto wrote:
> Am 24.01.2013 11:20, schrieb Walter Bright:
> >On 1/23/2013 9:10 PM, Era Scarecrow wrote:
> >>  I remember doing things like that. If I was dividing something by
> >>  8 I would shift right instead by 3;
> >
> >Compilers were doing that optimization 35 years ago, and probably
> >decades longer than that.
> >
> >Generally, if you're thinking about doing an optimization, it pays to
> >check the output of the compiler, as it has probably beaten you to it
> >:-)
> 
> 
> It helps to have a broader experience in many languages.
> 
> I think C only developers tend to suffer from premature optimization
> disease. :)
[...]

I remember being actually offended when I read about premature
optimization. I felt insulted at the idea that my hand-written code
could actually underperform what the compiler mechanically produces. Too
bad it's actually true. :-P

I later learned that my obsession with premature optimization distracted
me from actually thinking about the algorithms, so that I was spending
90% of my time optimizing the last CPU cycles out of an O(N^2) algorithm
when even a poorly-written O(log N) algorithm would have easily
outperformed my "optimized" code.

Not to mention the humiliation of discovering, when I actually profiled
my code, that the hotspots were nowhere near where I thought they were.
I had spent 90% of my time "optimizing" for a <1% gain, when a simple
algorithm fix at the real hotspot gained 20% instantly.


T

-- 
MSDOS = MicroSoft's Denial Of Service


More information about the Digitalmars-d mailing list