Results 1 to 3 of 3

Thread: Foreach performance

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Foreach performance

    Hi, I have to do several long iterations in a not so powerfull device and I'm a bit worried about performance.

    What's better? use a normal for or use foreach instead. For example, iterating all over a list.

    Foreach seems to be the answer... but it makes a copy, so it needs extra memory.

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Foreach performance

    Quote Originally Posted by jano_alex_es View Post
    Foreach seems to be the answer... but it makes a copy, so it needs extra memory.
    Yes, but since most of the Qt classes uses implicit sharing it isn't a problem. Just make sure you use const! this will save a lot of time.
    And if that is still to slow for you, use const STL-style iterators, they are the fastest. And if you think that your source code is unreadable with STL iterators, make a quick benchmark on your device and see if they are really quicker.

  3. The following user says thank you to Lykurg for this useful post:

    jano_alex_es (17th November 2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Foreach performance

    read this post, but it deals with Qt classes.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    jano_alex_es (17th November 2009)

Similar Threads

  1. QGraphicsView performance in 4.6
    By Lodorot in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2009, 23:09
  2. Performance trouble in Graphics View
    By zgulser in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 22:11
  3. QT core lib performance?
    By Quentin in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2009, 09:17
  4. Performance Issues in Qt-4.4.3 / Qwt-5.1.1
    By swamyonline in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 17:50
  5. Qt4 poor printing performance
    By seneca in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2009, 14:23

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.