Re: how to speed up some lisp code?
From: Will Hartung (willh_at_msoft.com)
Date: 02/19/04
- Next message: Hartmann Schaffer: "Re: Which free common lisp do you recommend?"
- Previous message: Barry Margolin: "Re: how to speed up some lisp code?"
- In reply to: John H Palmieri: "how to speed up some lisp code?"
- Next in thread: John H Palmieri: "Re: how to speed up some lisp code?"
- Reply: John H Palmieri: "Re: how to speed up some lisp code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 Feb 2004 15:53:08 -0800
"John H Palmieri" <palmieri@math.washington.edu> wrote in message
news:s5twu6k12gw.fsf@zeno1.math.washington.edu...
> I'm a mathematician, and I want to do some computations (using lisp,
> specifically Allegro, since that's what we have installed). In fact,
> I have written code for doing the things I want, but it's too slow, so
> now I would like advice on how to speed things up. I'll explain what
> sort of things I'm working with, and I'm wondering about good ways to
> deal with them. I think my main question is, how should I represent
> each sort of structure? For each data type, should I use defstruct
> or defclass, or just represent it as a list, or an alist, or a hash
> table?
A lot of these questions are generic algorithm questions, and not
necessarily at this stage Lisp specific.
You mention that you have a lot of ordered collections.
Are these dynamic collections, or static? Basically, if you're sorting
things over and over again, it may be faster to simply keep your structures
in an ordered data structure, that way they're always sorted.
Also, it's not clear whether you're doing much random, or keyed access to
your data versus simply iterating it.
I'm guessing as a complete swag that switching to more of a generic tree
structure rather than a unsorted list structure may be a hot tip and give
you a noticable performance boost. A tree structure will give you the
ability to iterate through the elements in a sorted order, as well as the
ability to pick elements out efficiently by key if that's necessary. Also,
adding data to the tree can be more efficient that something like append
which needs to scan the entire structure. Plus by reusing the tree
structures in place, you'll probably save consing of memory as well.
It also shouldn't have a draconian effect on your current code structure, so
ideally should drop in pretty painlessly.
There's a Red-Black tree library up on cliki.net
(http://www.cliki.net/Red-Black-trees) you might want to try for inspiration
(I've never used it). This tree algorithm is one of several that has the
advantage of keeping access times of data basically constant once the tree
is populated compared to an unbalanced tree.
I didn't want to go in to the hows and why of tree algorithms et al guessing
that you'd rather have a more black box approach to the problem than the
gritty details.
Regards,
Will Hartung
(willh@msoft.com)
- Next message: Hartmann Schaffer: "Re: Which free common lisp do you recommend?"
- Previous message: Barry Margolin: "Re: how to speed up some lisp code?"
- In reply to: John H Palmieri: "how to speed up some lisp code?"
- Next in thread: John H Palmieri: "Re: how to speed up some lisp code?"
- Reply: John H Palmieri: "Re: how to speed up some lisp code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|