Too much of a good thing? Sergei Egorov (10 Apr 2003 07:20 UTC)
Re: Too much of a good thing? Per Bothner (11 Apr 2003 05:54 UTC)
AW: Too much of a good thing? Michael Burschik (11 Apr 2003 07:35 UTC)
Re: AW: Too much of a good thing? Per Bothner (11 Apr 2003 15:18 UTC)
AW: AW: Too much of a good thing? Michael Burschik (14 Apr 2003 08:32 UTC)
Re: Too much of a good thing? David Rush (23 Apr 2003 09:21 UTC)
Re: Too much of a good thing? Taylor Campbell (15 Apr 2003 02:16 UTC)

AW: Too much of a good thing? Michael Burschik 11 Apr 2003 07:34 UTC

> Sergei Egorov wrote:
> > <Flame>
> > I think that most of the operations that generate vectors
> element-by-element
> > are useless, especially when the performance is the same as
> in making a list
> > first and then turning it into a vector.
>
> - which of course is never.

Correct me if I'm wrong, but R5RS does not provide resizable vectors, and
functions generating vector element by element have no way of knowing the
length of the resulting vector beforehand. If you want to write portable
code, this means you can either create n vectors of length 1 .. n and
discard all but the last, or create a list and then convert it to a vector
before returning it, which is, in fact, what the reference implementation
does. Are you sure that the first alternative is more efficient?

> > The reason for the existence of vectors
> > is constant-time access by index and smaller memory
> footprint; everything
> > else is better done with lists.
>
> I'd say: (almost) everything is better done with vectors, if you
> care about performance at all.

Only if you know how large your data structures are going to be. If you
constantly have to resize your vectors, or create new vectors of an
appropriate size, your performance might not be so stellar.

> > I suggest to drop everything that is not related to the main purpose
> > of vector's existance: constant-time indexed access.
>
> Linear-time operations, such as iterating over all the elements of a
> sequence, are also typically much faster using vectors, thanks
> to better cache utilization.

But iterating over all elements of a sequence is an example of exploiting
constant-time access to the elements of the sequence. Otherwise, one would
recurse over the sequence.

Regards

Michael Burschik