Paul Millar wrote:
> 
> On Wed, 20 Mar 2002, Allan Whiteford wrote:
> > Is their not a difference between optimising a piece of code (in a
> > textbook computer science type way) and choosing the correct algorithm
> > (by actually engaging your brain)?
> 
> (IMHO) sort of ...
> 
> > I'd say they were different things but I wouldn't like to have to draw a
> > line anywhere between them.
> 
> Yes, I agree. In practise there is a difference, but conceptually there
> isn't.
> 

I think there are conceptual differences.

As an example of a purely computational optimisation of a piece of code
consider finding the total of all the elements in a 10x10 array.

The algorithm would be as follows:

"Set the total to zero. Go through each of the elements in turn and add
it's value to the total".

2 possible implementations of this are:

total=0;
for (i=0;i<=9;i++)
{
        for (j=0;j<=9;j++)
        {
                total=total+array[i][j];
        }
}

total=0;
for (i=0;i<=9;i++)
{
        for (j=0;j<=9;j++)
        {
                total=total+array[j][i];
        }
}

The first solution will be faster but the algorithm hasn't changed. It's
just about knowing the language/compiler. However, once you go to
something complicated I think it's hard to label an optimisation as
being purely computational or something to do with the algorithm; it
just becomes a big grey area.

> 
> Yep, the right tool for the right job. As long as you sort out the higher
> level stuff (which algorithm to use), let the compiler sort of some of the
> nitty gritty detail.

I agree completely. Nobody wants to unroll their own loops :).

Thanks,

Allan
-- 
Intel: We put the 'um...' in Pentium.
--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------

Reply via email to