Kelsey Bjarnason wrote:
> Phlip wrote:
>
> > Premature optimization is the root of all evil. STL wouldn't exist if it
> > weren't as fast as the alternative (raw arrays for std::vector,
>
> Simple local testing reveals that inserting objects into a vector via
> push_back is approximately 8 times slower than simply storing them into an
> array and a simple loop and increment ( for i = 0 to nelems; inc elem )
> runs a good three times slower with vectors.
Set the capacity first. That's cognitively the same thing you do with a
fixed-size array. You compared a vector to calling new over and over again.
> Speed isn't the key to the STL. The fact that it provides reasonable
> speed, plus a very rich set of operations and relieves the coder from
> managing all the gory details seems a little more significant.
Speed is the key. Vendors may implement containers however they see fit, but
each container type has a performance profile guaranteed to match an
equivalent "manual" data structure. vector iterates as quickly as an array,
and accesses randomly as quickly as an array. list can delete a middle
element as quickly as a linked list can pull out an inner node. Etc.
--
Phlip
http://industrialxp.org/community/bi...UserInterfaces