[ Re: [Maxima] Maxima speed]



I neglected to cc to list...

-------- Original Message --------
Date: Fri, 11 Jan 2002 10:46:26 -0800
From: Richard Fateman <fateman at cs>
Organization: University of California, Berkeley
To: Martin Rubey <a9104910@unet.univie.ac.at>
Subject: Re: [Maxima] Maxima speed

If you want to make programs fast, a really good idea
is to ignore your intuition and profile them first.  That is,
take some representative problems and run them through
you program, and use tools to see where the time is taken.
Typically 90% of the time is taken in 10% of the code.
Then consider if you want to rewrite that 10%.  Any
time spent on the rest of the code is basically wasted, since
you cannot improve the running time by more than 10%.

So it may be appealing to think that position_if should
be replaced, it is not obvious to me that reprogramming
it is the key.


It may be plausible to use arrays or vectors or some other
data structure rather than lists, if the lists become really
long and you are constantly pasting things on the end.  Another
approach that sometimes helps is to build lists backwards,
since (cons x  longlist)  is cheap, but  (nconc longlist (list x))
takes time proportional to length of longlist. It may also be
worthwhile to store the length of a list along with it, rather
than computing its length each time.

It is possible to reverse a list in place rapidly after everything
else is done.

But profiling is the first priority.
(Actually the very very first priority is getting the program
to provide the right answers.  And also to decide if the program
is already fast enough.
)

If you have some long-running burge.lisp inputs, I would
be willing to profile the problem.
RJF

PS, I tend to think that lisp is more readable, too. Obviously
this would not be the case for people totally unfamiliar
with lisp!