On Wed, 20 Mar 2002, Graeme Mathieson wrote:

> On Wed, Mar 20, 2002 at 01:19:37PM +0000, Paul Millar wrote:
> >
> > (e.g. use your brain to optimise code, not
> > the -O2 switch in gcc).
>
> Bah.  The -O2 switch in GCC will do a lot better than most people trying
> to hand optimise code.  The important thing to do is write the code in
> the first place.  Once that's done, you can use a profiler to determine
> which areas it's actually worth spending time on optimising.
>
> I worked with somebody who preferred to 'optimise' his own code.  He
> produced unreadable piles of crap and spent ages 'optimising' code that
> was never in the critical path.  I seriously doubt what he was producing
> was any faster than a decent compiler would anyway...

Yes, but there's optimising and optimising. It's certainly normally
better to let your wonderful optimising compiler handle the little
details. But that is pointless unless the code is written sensible in
the first place.

My point is, before rushing into coding something, choose a sensible
algorithm to do it. Or find somebody else's which already does it. You
needn't spend a long time, but thinking about what algorithms (and of
course data structures) you use should help you produce better and
clearer code. Which will be faster than a stupid algorithm with
any compiler optimisations.


-- 
Nicholas Wolverson

--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------

Reply via email to