[Tutor] Simplicity vs. Speed

alan.gauld@bt.com alan.gauld@bt.com
Tue, 15 May 2001 11:18:43 +0100


> From: Remco Gerlich [mailto:scarblac@pino.selwerd.nl]
> On  0, Phil Bertram <phil.bertram@clear.net.nz> wrote:
> > get the code working bug free, and not worry at all about speed ?
> 
> Programmers, even very experienced ones, have misguided 
> intuitions about where the bottlenecks in their programs are. 

This is soooo true.
In fact on large systems the bottlenecks are usually in the 
database or network, not the code at all!

> In my opinion, it should work like this in most cases:
> - Make the simplest thing that could possibly work.
> - *If* this turns out to be too slow, *find out what slows it down*.
> - Try to find out a better algorithm.
> - Repeat.

I agree with Remco's comments except I would add that as well 
as the algorithm consider your data structures - very often 
they will force the algorithm and if they are inappropriate 
no amount of algorithm tweaking can fix it. eg. Using a 
dictionary is often much faster than looping thru' a list 
for example. Could you change your top level lists into 
dictionaries (keyed by date mebbe?)

But first get the code working. Then if, and only if, its too 
slow (based on what? User feedback?) locate the hot spots 
and fix them.

Alan G