searching for article...

M

moswald

I've been searching for a specific article for awhile now. About two
years ago (maybe longer) there was an article in the C/C++ User's
Journal that compared the performances of various stl containers.
Unfortunately, while I remember the topic, I don't remember much else,
so if anyone is inclined to help me find it, they'll have to do some
detective work. I remember it was co-written by two people, one of
which I *think* is Herb Sutter (but I may be way off-base on that).
I'm not positive if it was in the CUJ, either, as it could have been
Dr. Dobbs. I doubt it was in any other magazine, as I remember
reading it at work and at the time we only subscribed to those two.

Specific information about the article: it noted that while list was
better for insertion in the middle, it turns out that vector is almost
always fast enough. And by that I mean fast enough that the article
recommended just always using vector.

I'd like to reread this article, and it's driving me batty that I
can't just google "vector list comparison c++ article" and get
anything useful.
 
V

Victor Bazarov

I've been searching for a specific article for awhile now. About two
years ago (maybe longer) there was an article in the C/C++ User's
Journal that compared the performances of various stl containers.
Unfortunately, while I remember the topic, I don't remember much else,
so if anyone is inclined to help me find it, they'll have to do some
detective work. I remember it was co-written by two people, one of
which I *think* is Herb Sutter (but I may be way off-base on that).

If you aren't, you will find the article here:
http://www.gotw.ca/publications/index.htm
I'm not positive if it was in the CUJ, either, as it could have been
Dr. Dobbs. I doubt it was in any other magazine, as I remember
reading it at work and at the time we only subscribed to those two.

Specific information about the article: it noted that while list was
better for insertion in the middle, it turns out that vector is almost
always fast enough. And by that I mean fast enough that the article
recommended just always using vector.
Interesting...

I'd like to reread this article, and it's driving me batty that I
can't just google "vector list comparison c++ article" and get
anything useful.

What if you add 'CUJ' to that? Or more of 'container' 'standard'
and some such?

V
 
M

moswald

If you aren't, you will find the article here:http://www.gotw.ca/publications/index.htm

Thanks for the link. I've searched there, and I'm starting to think
that I was incorrect about him being one of the authors.
Interesting...

Yeah, which is why I want to reread it. I want to make sure I'm not
crazy, and the article really did recommend it.
What if you add 'CUJ' to that? Or more of 'container' 'standard'
and some such?

I don't know if I've tried permutations of 'container', I'll do some
more searching. Thanks for the idea.
 
G

Guest

I've been searching for a specific article for awhile now. About two
years ago (maybe longer) there was an article in the C/C++ User's
Journal that compared the performances of various stl containers.
Unfortunately, while I remember the topic, I don't remember much else,
so if anyone is inclined to help me find it, they'll have to do some
detective work. I remember it was co-written by two people, one of
which I *think* is Herb Sutter (but I may be way off-base on that).
I'm not positive if it was in the CUJ, either, as it could have been
Dr. Dobbs. I doubt it was in any other magazine, as I remember
reading it at work and at the time we only subscribed to those two.

Specific information about the article: it noted that while list was
better for insertion in the middle, it turns out that vector is almost
always fast enough. And by that I mean fast enough that the article
recommended just always using vector.

I just watched an interesting video [*] of a presentation that Sutter
did where (at the end) he talked about that, he also mentioned that some
or all the information from the talk would be in a DDJ article (the 3rd
or 4th instalment of the Effective Concurrency series).

If we are talking about the same thing then the point he was making was
that due to cache latency (and RAM for large collections) and the
speculative prefetching modern CPUs performs a traversal of a vector
from start to end (or in reverse) will be much faster (different
magnitude) then a traversal of a list or other node-based structure.

So if you will perform many traversals of the container but very few
insertions in the middle then a vector will be much faster, however if
you do only a few traversals but many insertions in the middle then I am
not so sure. As always (and as Sutter said) always measure.

* The video:
http://video.google.com/videoplay?docid=-4714369049736584770
Slides:
http://www.nwcpp.org/Downloads/2007/Machine_Architecture_-_NWCPP.pdf

The thing about efficiency of a list vs. a vector begins about one
and a half hour in (or page 22 of the slides).
 
J

James Kanze

On 2007-11-01 17:43, (e-mail address removed) wrote:

[...]
If we are talking about the same thing then the point he was
making was that due to cache latency (and RAM for large
collections) and the speculative prefetching modern CPUs
performs a traversal of a vector from start to end (or in
reverse) will be much faster (different magnitude) then a
traversal of a list or other node-based structure.

A vector generally does have better locality, but some list
implementations use various strategies to improve the locality
as well. Note too that if the objects in your vector use
dynamic memory (e.g. a vector of std::string), then you may not
have the locality anyway, even with vector.
So if you will perform many traversals of the container but
very few insertions in the middle then a vector will be much
faster, however if you do only a few traversals but many
insertions in the middle then I am not so sure. As always (and
as Sutter said) always measure.

Always measure. If your copy constructor and assignment
operator are very expensive (e.g. a deep copy of dynamically
allocated memory), insertion in the middle of a vector becomes
very expensive. If they're cheap (e.g. for int), you have to
copy an awful lot for the cost to be as high as the dynamic
allocation a list typically needs (but here, too, some
implementations have more or less effective optimization
strategies).

Anytime you read global statements as to which container is
faster, be suspicious, because the only correct global answer
is: "it all depends".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top