Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHash - Lost performance on Ubuntu
Forum Updated to NodeBB v4.3 + New Features

QHash - Lost performance on Ubuntu

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tchoninho
    wrote on last edited by
    #1

    Hi everybody,

    I have a code that run in a portable application (Ubuntu 12 and windows 7).
    This application was compiled using VC++ 2010 and Qt 4.7 for Windows and for Ubuntu using g++ 4.4 and Qt 4.8.
    Optimization flag setted as O2 (on both environments).

    I have a QHash data structure and two algorithms to looking up its.

    The first algorithms looking up by keys and the other by values. The choice between theses two algorithms is done by a statistic function.
    In the tested code I need to perform a looking up by values and the result on Ubuntu is 5 times slow than on Windows ones.

    Windows 7: 102.19 ms
    Ubuntu 12: 505.71 ms

    My structure is something like this and the performance analysis was done in "perform()" method:

    @
    class InnerObject
    {
    public:
    QString key;
    double value;

    InnerObject();
    ~InnerObject();
    

    };

    class MyObject
    {
    public:
    MyObject();
    ~MyObject();

    private:
    QHash<QString, InnerObject*> inner;
    int id;
    };

    class Collection
    {
    public:
    Collection();
    ~Collection();

    void perform(){
    // (...)
        for(MyObject *myObj, collection.values()) {
    
            if (myObj) {
            // do something...
        }
    }
    

    }

    private:
    QHash<int, MyObject *> collection;

    };
    @

    Anyone knows what is happening??

    Thanks!

    Computer Scientist
    Belo Horizonte - Brasil
    C++ Development
    Qt Development

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      There are two thing I would try.

      • Refactor the code to using <code>foreach</code> or an iterator (not <code>.values()</code>)
        @
        foreach(MyObject* myObj, collection)
        ...

      for (QHash<int, MyObject *>::Iterator myObj = collection.begin();
      myObj != collection.end();
      ++myObj)
      ...
      @

      • Move away from the ancient GCC 4.4 to 4.6 or better 4.7.
      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        To get even more performance, use Qt5 built with C++11 support (GCC 4.7/ 4.8 or clang). Hints from Lukas are even better, though :)

        (Z(:^

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tchoninho
          wrote on last edited by
          #4

          Lukas,

          I changed 'foreach' by iterator and ran a little test on windows. The performance improves in ~33%.

          Sierdzio,

          Changes my 3rd party libraries isn't a possibility for now.

          I'm running the real test now... after analysis I will post here...
          Thanks!!

          Computer Scientist
          Belo Horizonte - Brasil
          C++ Development
          Qt Development

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tchoninho
            wrote on last edited by
            #5

            Hi guys,

            I tested on Ubuntu 12 and on Windows 7 but the performance not changed.

            The real improvement not happened. The 33% said, occurr only when I looking up by key in some situations..

            Computer Scientist
            Belo Horizonte - Brasil
            C++ Development
            Qt Development

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              How about using a datastructure that is actually optimized for iteration over all elements?

              Fiddling with making QHash fast for this use-case is bound to be micro-optimizations only.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tchoninho
                wrote on last edited by
                #7

                [quote author="Tobias Hunger" date="1363983457"]How about using a datastructure that is actually optimized for iteration over all elements?[/quote]

                Tobias, I have two algorithms that may be used and one of them is chose in runtime (by statistical function). Hash was chose because its complexity and there are moments that I get the object by key too.
                There is always a trade-off that must be considered as everything in computing.

                [quote author="Tobias Hunger" date="1363983457"]Fiddling with making QHash fast for this use-case is bound to be micro-optimizations only.[/quote]
                I don't discover yet what is the problem between platforms but the same code is faster on Windows and very slow on Ubuntu.

                On my tests, I could see that the problem isn't in the hash per si. This should be in the hash implementation, Ubuntu's scheduler, both or another thing.

                []'s

                Computer Scientist
                Belo Horizonte - Brasil
                C++ Development
                Qt Development

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved