Results 1 to 9 of 9

Thread: QList < QHash < int, QString> > ... clear() is slow

  1. #1
    Join Date
    Jun 2009
    Posts
    37
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QList < QHash < int, QString> > ... clear() is slow

    I'm translating an old application into qt...
    I started doing a QList < QString > as it was the original algorithm, but this was meaning looking into the string everytime I needed a value.

    I now translated the <QString> into a QHash <int, QString>, witch applies perfectly to my purpose...

    BUT NOW...

    When I do QList::clear() ... this turn into an extremely slow operation, 3x more slow then keeping my old algorithm.

    What can I do to improve performances of clear() ??? Does it dependes on QList or on QHash???

    Do I have to turn into a QSqlTableModel??? But this would mean to break all old algorithms and the Boss wouldn't be happy
    Last edited by JoZCaVaLLo; 14th March 2011 at 16:08.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    QList::clear()? What QList? You said you had a QHash...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2011
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    You replaced a list of strings with a list of hashes? Or just a single hash, with the old index as the key? How did your non-qt algorithm find strings without looking at them? If it was just a lookup by index, why can't you just do that with QList<QString>? what does QSqlTableModel have to do with anything? In short, you're missing a lot of information, and I'll bet dollars to donuts clear() isnt your problem.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    Mmmmm doughnuts

    I think the final structure was QList< QHash<int, QString> > and that the clear() method is being called on the outer QList. This would result in the destructor of each QHash being called, which would in turn call the destructor of each QString. If there is a list of hundreds of hashes of hundreds of keys then the numbers get large quickly but still should not be a massive imposition unless you do it repeatedly.

  5. #5
    Join Date
    Jun 2009
    Posts
    37
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    Thank you all for your answers.

    The main point is that now I represent a table with a QList < QHash <int, QString> >. This has improved performances until I call QList::clear(), this is so slow that at the end, the overall performances are much better with the old program (about 3x better!!!!!!!!!!)

    The QHash can have a length of max 30. But the QList is about 200'000 elements. The clear() of such a QList takes about 20 minutes on a Intel 2.66 GHz 4 Gbytes Ram.
    The same QList, but with QStrings instead of QHashes, takes ~5 minutes.

    My question is: Do I have better time to
    1) reimplement the clear() of QHash and QList?
    2) keep the QList <QString> ?
    3) look for another container?
    Last edited by JoZCaVaLLo; 15th March 2011 at 08:28.

  6. #6
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    We can not give an correct answer without seeing the algorithm, but even this could only a guess. (Maybe you introduced a bug that has nothing to do with the new algorithm)

    You will get the best answer this way:

    1.) Run the program with a profiler and check were the bottleneck is (you will be suprised )
    2.) Optimize the bottleneck.
    3.) Repeat 1.) + 2.) until the performance is ok.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    Run the attached project and post your results. Mine are:
    ********* Start testing of HashListBenchmark *********
    Config: Using QTest library 4.7.0, Qt 4.7.0
    PASS : HashListBenchmark::initTestCase()
    RESULT : HashListBenchmark::clearHash():
    996 msecs per iteration (total: 996, iterations: 1)

    PASS : HashListBenchmark::clearHash()
    PASS : HashListBenchmark::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped
    ********* Finished testing of HashListBenchmark *********
    The test machine is:
    2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:39:03 UTC 2011 x86_64
    vendor_id : AuthenticAMD
    model name : AMD Phenom(tm) II X6 1055T Processor
    cpu MHz : 800.000 (2800 max)
    MemTotal: 4053732 kB
    Attached Files Attached Files
    Last edited by wysota; 15th March 2011 at 10:26.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    JoZCaVaLLo (15th March 2011)

  9. #8
    Join Date
    Jun 2009
    Posts
    37
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    Thanks Wysota
    The problem is running the app in debugging from Visual Studio:

    This is the result running your test without debugging

    ********* Start testing of HashListBenchmark *********
    Config: Using QTest library 4.6.3, Qt 4.6.3
    PASS : HashListBenchmark::initTestCase()
    RESULT : HashListBenchmark::clearHash():
    1,343 msec per iteration (total: 1343, iterations: 1)
    PASS : HashListBenchmark::clearHash()
    PASS : HashListBenchmark::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped
    ********* Finished testing of HashListBenchmark *********
    with debugging is still running after 30 minutes...

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList < QHash < int, QString> > ... clear() is slow

    Well, I'm not surprised. Debugging is slow.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Sort a QHash<QString, int> by value
    By Trader in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2010, 19:03
  2. how can i destruct QHash<QString, QPixmap>?
    By SamSong in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2010, 06:41
  3. How does QString::qHash() work?
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 09:17
  4. Fastest way to clear a QList
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 09:26
  5. Query about QHash , QList
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2006, 09:04

Tags for this Thread

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.