Let Go, Standard Library From Community

David B. Held dheld at codelogicconsulting.com
Thu Apr 19 19:58:34 PDT 2007


Stephen Waits wrote:
> [...]
> I agree with you.. portability is preferred here, considering the 
> non-existent performance difference.
> 
> I'd even go as far as saying that using bit twiddling in this specific 
> case is the "junior mistake".
> 
> Why?  Because it assumes that the compiler isn't already taking care of 
> this for you.
> [...]

To highlight this point, I interviewed a candidate the other day that 
agonized over the best way to return a vector from a C++ function in an 
efficient manner.  He considered heap-allocating it and returning a 
pointer (apparently, he thinks 'new' is fast), passing an out reference, 
and a few other things.  And yet, he didn't once mention the fact that 
he was passing *in* two vectors *by value*.  When I asked him the most 
efficient way to pass in the input vectors, I asked if he should do it 
by value, by reference, or by pointer.  He said: "By pointer".  Oy vai! 
  Apparently, he wasn't familiar with [N]RVO, and was optimizing the 
wrong thing.  90% of any given program contributes only 10% to its 
overall performance, typically.  That's why C.A.R. Hoare warned against 
the dangers of premature optimization (and making sure you optimize the 
*right* thing).

Dave



More information about the Digitalmars-d mailing list