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!!