Results 1 to 4 of 4

Thread: Performance in functions with QList

  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Performance in functions with QList

    Is there a significant performance issues between the next 2 functions ?


    Qt Code:
    1. void cos(QList<Complexo> &x, QList<Complexo> &y)
    2. {
    3. y.clear();
    4.  
    5. for(int i=0;i < x.size(); i++)
    6. {
    7. y.append(cos(x[i]));
    8. }
    9. }
    10.  
    11. QList<Complexo> cos(QList<Complexo> & x)
    12. {
    13. QList<Complexo> y;
    14.  
    15. for(int i=0;i < x.size(); i++)
    16. {
    17. y.append(cos(x[i]));
    18. }
    19.  
    20. return y;
    21. }
    To copy to clipboard, switch view to plain text mode 

    The second seems more elegant but returning a large QList, will be slower ?
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  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: Performance in functions with QList

    Go for the second variant. It is fast since QList is one of Qt's implicit data sharing class (In the docs under: Implicit Sharing). So only a pointer will be passed back and that is very fast

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

    john_god (31st July 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Performance in functions with QList

    If you're interested, here's some insight into QList:
    http://marcmutz.wordpress.com/2010/0...dered-harmful/

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

    john_god (31st July 2010)

  6. #4
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Performance in functions with QList

    Thanks Lykurg and tbscope. Second variant shall be .
    I checked MarcMutz link "QList considered harmful", didn´t know that. However there's some contradictions with Qt Nokia docs. Always thought QList was preferable to QVector. I have no experience with STL containers, never used them. So I'am sticking with QList, I like it's sintaxe better, and it suits my case.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Similar Threads

  1. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  2. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59
  3. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  4. QList<QList > question
    By SubV in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 15:14
  5. Mathematical Functions
    By krishbhala in forum Qt Programming
    Replies: 3
    Last Post: 11th January 2008, 13:55

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.