[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: Too much of a good thing?



> 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