Results 1 to 4 of 4

Thread: QVector Slower than STL Vector

  1. #1
    Join Date
    Nov 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QVector Slower than STL Vector

    Hey guys,

    I have a question regarding QVector. I switched from using STL vectors throughout a portion of my code to using QVector since the documentation mentioned it as being a more lightweight and faster container. However, when I performed the switch, I noticed about a 25% slowdown in my cross-correlation code performance. I've attached a sample bit of code which is the bottleneck. I worked pretty hard optimizing it with STL vectors, but I am unsure if due to implicit data sharing or other features of QVector, there may be an even faster way to do it. Thanks!

    (For example, this code takes around 4800 msec to run, versus 3200 msec for STL Vector).

    Qt Code:
    1. void corr_dcc(
    2. const QVector< QVector<quint16> >& IA,
    3. const QVector< QVector<quint16> >& IB,
    4. QVector< QVector<qreal> >& map)
    5. {
    6. quint16 i, j, x, y;
    7. quint16 wind_xsize = IA.size();
    8. quint16 wind_ysize = IA.at(0).size();
    9. quint16 xshift = IB.size() - wind_xsize;
    10. quint16 yshift = IB.at(0).size() - wind_ysize;
    11.  
    12. for(x = 0; x < xshift; x++) {
    13. for(i = 0; i < wind_xsize; i++) {
    14. const quint16* IA_i = &IA.at(i).at(0);
    15. const quint16* IB_ix = &IB.at(i + x).at(0);
    16. for(y = 0; y < yshift; y++) {
    17. qreal& map_yx = map[x][y];
    18. for(j = 0; j < wind_ysize; j++) {
    19. map_yx += ((qreal) IA_i[j]) * IB_ix[j + y];
    20. }
    21. }
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QVector Slower than STL Vector

    If performance is the primary concern, you should use plain old pointers instead of more complex objects. The latter always have additional overhead associated with them.

    I'm not sure why you're using 16-bit ints, either. These short integers may not perform as well as whatever int corresponds to on a particular platform, although this isn't a hard and fast rule.

    Finally, correlation routines are often faster in the Fourier domain if the arrays involved are large. You have to experiment to find the break-even point, but this can often yield a significant speedup.

  3. #3
    Join Date
    Nov 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QVector Slower than STL Vector

    Thanks for the reply,

    I'm aware of FFT correlation algorithms, however I'd like to get this algorithm working first because it is faster for small sample areas.

    What would be an example of writing that code using simpler objects? I tried using pointers in the most intensive parts of the code. Still, I find it interesting that simply changing from std::vector to QVector (the only change!) caused a 25% slowdown.

    Thanks for the tip about 16-bit ints. I wasn't aware of that, but I'll try it and see if it speeds up. Thanks!

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVector Slower than STL Vector

    Did you do these speed tests in debug or release mode? Debug mode is likely to be slower for QVector.

  5. The following user says thank you to squidge for this useful post:

    Phlucious (2nd December 2011)

Similar Threads

  1. Qt 4.6.3 slower than 4.6.2
    By Nik8768 in forum Installation and Deployment
    Replies: 3
    Last Post: 19th July 2010, 12:13
  2. why Qt4 is so slower than Qt3 ?
    By xuyaojun1980 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th February 2009, 18:32
  3. vector of vector and computes
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th May 2008, 12:47
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 08:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.