[Development] Container benchmark was HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Alejandro Exojo
suy at badopi.org
Sun Jul 12 23:19:53 CEST 2015
El Sunday 12 July 2015, Thiago Macieira escribió:
> On Sunday 12 July 2015 16:16:07 Smith Martin wrote:
> > I can see by your explanation that QVector is almost always more
> > efficient than QList. But sometimes the difference doesn't matter.
>
> If it doesn't, then why not choose QVector?
I've carefully read the thread, and I think the issue Martin or others might
have is:
* Documentation and the common know how about Qt containers tells that QList
is a reasonable middle ground choice (sometimes is like a vector, sometimes
like a linked list/vector hybrid). Is what the docs say, what the Qt Quarterly
article says (which is old, but Olivier gave a recent explanation on
containers on 2012's devdays), what is being used in the API as return type,
etc.
* Marc has been criticizing what the docs says, but even being a significant
contributor to Qt, did not propose to change that.
* According to Martin's explanations, he did send a patch for qdoc that
replaced a wrong choice of container, but the change did not have any apparent
effect.
* We are having a large thread with a heated discussion, and Marc said things
like "and the resulting code will be highly fragile and/or extremely
inefficient". People might felt a bit offended by that. Is something being
said about their work, after all.
To summarize:
I not sure whether you (plural) think that no container should be advised as
the preferred one, or if it should be QVector, though.
I think that you, and others who have voiced their opinions agree with Marc on
vectors being better that what first intuition will tell you ("use of a list
if you have changes in the middle or the beginning is not as right as it might
seem due to caches"). That's something that Stroustrup explained very well,
e.g.:
https://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-
Stroustrup-Cpp11-Style (from minute 45 more or less)
In that talk, he shows that std::vector is better than std::list for _all_ N,
and is an exercise where insertions and deletions happen in the middle. He
does explain that what dominates is the search for the insertion/removal
point. That should be quite different with QList.
But Stroustrup _does_ insertion and removals in the middle. Marc's benchmarks
only do appends, and the says:
> I also didn’t test insertions in the middle, since they’re rather rare.
> That said, there are of course lots of other tests one could run (e.g.
> sorting), and I invite you, dear reader, to implement some of them in the
> test harness and contribute them back.
Well, I certainly don't understand why that's irrelevant. And I think we would
not be having this conversation if it were that clear.
I *do* really find this discussion interesting, but what I really, *really*
want is to have the best documentation possible, and if we can't agree on
which container should be preferred as a first choice, let's remove that and
move on.
--
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net
More information about the Development
mailing list