> Von: development-bounces+helmut.muelner=joanneum...@qt-project.org
> [mailto:development-bounces+helmut.muelner=joanneum.at@qt-
> project.org] Im Auftrag von André Pönitz
> Gesendet: Donnerstag, 21. Juni 2012 02:00
> An: Marc Mutz
> Cc: development@qt-project.org
> Betreff: Re: [Development] Container refactor update [Caution: Message
> contains Suspicious URL content]
> 
> On Thu, Jun 21, 2012 at 01:06:16AM +0200, Marc Mutz wrote:
> > On Thursday June 21 2012, André Pönitz wrote:
> > > On Wed, Jun 20, 2012 at 08:52:55AM +0200, Marc Mutz wrote:

> [...]
> 
> #include <QList>
> #include <QVector>
> #include <math.h>
> 
> struct A
> {
>     A() : a(sin(12)) {}
>     A(const A &b) : a(sin(b.a) + cos(b.a)) {}
>     int a;
> };
> 
> struct Foo
> {
>     A a[100];
> };
> 
> int list()
> {
>     QList<Foo> f;
>     for (int i = 0; i != 10000; ++i)
>         f.append(Foo());
>     return f.size();
> }
> 
> int vector()
> {
>     QVector<Foo> f;
>     for (int i = 0; i != 10000; ++i)
>         f.append(Foo());
>     return f.size();
> }
> 
> int main()
> {
>     return list() + vector();
> }
> 
> callgrind just came up with a 3:1 advantage _in favour_ of QList.
> 
> And that ratio can be made look arbitrarily worse by adding more load to the
> copy constructor.
> [...]

I measured this programming using MSVC2010 with /Ox and Rational Quantify and 
also the a 3:1 factor.
But: QList::append calls new 10000 times, QVector::append never calls new but 
QVectorData::allocate twice and QVector::realloc once.
If I add f.reserve(10000) in both cases, QList::append still call new 10000 
times, and QVectorData::allocate is still called only twice, and QVector is 
faster than QList (by a small but consistent margin).
Without optimization QVectorData::allocate is call 24 times (for the first 
case, still 3:1).

This looks like MSVC2010 can optimize away QVector resizes. And you can get 
arbitrary results if you make the constructor heavier and the copy constructor 
lighter.

Best regards,
Helmut


_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to