Results 1 to 9 of 9

Thread: Qt g++ optimization

  1. #1
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt g++ optimization

    I hav developed an application for which performance is a constraint .Is there any method to optimize the g++ of Qt..Any ideas....I hav tried modifying makefile g++ FLAGS with -O3 -ffast-math -funroll-loops to optimize the code..But the performance is the same.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    If you ut it this way, there isn't much you can improve with compiler options. This is more like a "cosmetic" option.
    Usually, from my experience, the layouts are the slowest in Qt. I mean complex nested layouts.

    Have you profiled your application to see which parts take the longest time to execute?

    Maybe there are some parts in your code that can be optimized to run faster.
    You should provide more details, such as what is not optimal in your opinion.

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    Quote Originally Posted by Krish_ng View Post
    I hav developed an application for which performance is a constraint .
    Then optimize your code... compiler tries their best to optimize the assembly output but they cannot refactor your code... you can spot where CPU time is spent through various tools (for instance Valgrind) and then optimize the faulty code.

    p.s. : v=looks like a double thread to me... you should avoid this for it won't make answers come any faster...
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    My application has a scroll which takes time ...i hav used getTimeofday() to get the time of
    execution for the scroll.The scroll is done in eventfilter.When i used -ffast-math and -funroll-loops thers was a little diff in time..So if i can disable some of g++ flags,it may perform better.i guess....Any idea wat are the default flags enabled for 02...

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    Could you post some code?
    I am sure this can be solved by optimizing the code rather than testing gcc flags.

    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    Quote Originally Posted by Krish_ng View Post
    My application has a scroll which takes time ...i hav used getTimeofday() to get the time of
    execution for the scroll.The scroll is done in eventfilter.When i used -ffast-math and -funroll-loops thers was a little diff in time..So if i can disable some of g++ flags,it may perform better.i guess....Any idea wat are the default flags enabled for 02...
    If you want to see by yourself how much time is spent doing a precise task use QTime :
    Qt Code:
    1. t.start();
    2.  
    3. // do some things here
    4.  
    5. qDebug("things tooks %i ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    And, as I said already, investigate your code. If your algorithms are a mess, no matter how much they are optimized by the compiler, they will still waste a lot of CPU time... Unless you can't afford showing your code for any reasons you'd better post it here so that someone might suggest improvements...
    Current Qt projects : QCodeEdit, RotiDeCode

  7. #7
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    Qt Code:
    1. bool QMyView::eventFilter(QObject *target, QEvent *event)
    2. {
    3.  
    4. if (event->type() == QEvent::KeyPress)
    5. {
    6. //typecast QEvent to QKeyEvent
    7. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    8. //following are checking for target widget where event happens
    9. //checks whether target is listwidget
    10. if(target==this)
    11. {
    12. //checks whether pressed key is 1
    13. if (keyEvent->key() == Qt::Key_1 )
    14. {
    15.  
    16. m_pMyViewButtonBar->showDialog(this);
    17.  
    18. here i am using an instance of a splitter to show a dialog
    19. }
    20. else
    21. {
    22. //checks whether pressed key is down
    23. if (keyEvent->key() == Qt::Key_Down )
    24. {
    25. //checks m_count is for number of items upto down scroll to be done
    26. if(m_iCount!=-1 && m_iCount<23)
    27. {
    28. / /each time 10 items are get scrolled down
    29. m_iCount=m_iCount+10; updateAllMyMainWindowViews(m_iCount,m_iCount+15);
    30. //place where time is spent for execution
    31. }
    32. }
    33. //checks whether pressed key is down
    34. else if(keyEvent->key() == Qt::Key_Up)
    35. {
    36. //checks m_count is for total number of items upto up scroll to be done
    37. if(m_iCount>0)
    38. {
    39. //each time 10 items are get scrolled up
    40. m_iCount=m_iCount-10;
    41. updateAllMyMainWindowViews(m_iCount,m_iCount+15);
    42. }
    43. }
    44. //checks whether pressed key is alt
    45. else if(keyEvent->key() == Qt::Key_Alt)
    46. {
    47. //checks itemcount is not eqalto -1
    48. if(m_iCount!=-1)
    49. {
    50.  
    51. updateAllMyMainWindowViews(m_iCount,m_iCount+15);
    52. }
    53. }
    54. }
    55. }
    56.  
    57. }
    58.  
    59.  
    60.  
    61. void QMyView::updateAllMyWindowViews(INT32 start,INT32 end)
    62. {
    63.  
    64. //From event filter i am trying to updte tha list items
    65. //in event i am trying to update the listwidget items..The listwidget is added to a splitter
    66. m_pSplitterView->updateFirstView(start, end);
    67. m_pSplitterView->updateSecondView(start, end);
    68. m_pSplitterView->updatethirdView(start, end);
    69. m_pSplitterView->updateFourthView(m_iScrollInitialValue, m_iScrollMaxValue);
    70.  
    71. }
    To copy to clipboard, switch view to plain text mode 



    I hav an application with a splitter that has 4 listwidgets.I am trying to update 14 items on each scroll,using ScrollToitem in the update methods...How can reduce this scroll time
    Last edited by wysota; 8th August 2007 at 22:52.

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    First of all: eventFilter is reentrant. Meaning that you modify a widget inside it, then it will reenter.

    Second of all: you install a widget as an eventfilter for itself( target == this ). This is not OK. Use event() instead if you want to catch key presses for a widget.

    Try not to show dialogs from inside event handlers. Also do not modify widgets in event handlers. This could lead to recursion. Therefore your program's lagging.

    Regards

  9. #9
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt g++ optimization

    I hav changed my code and hav used keyPressEvent instead of eventFilter...I need to show
    a dialog when Key_1 is pressed. Then should i give dilaog->show() in event or some other place...I even want show a scroll of 10 items when up and dwn keys..Then i should
    update the list items in event ????Any ideas

Similar Threads

  1. g++ optimization
    By Krish_ng in forum Qt Programming
    Replies: 6
    Last Post: 31st August 2012, 09:01
  2. Need Qt Optimization for 32MB ram Machine
    By rajeshs in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2007, 05:56
  3. Optimization specifics with qmake
    By bitChanger in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2006, 17:55
  4. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09: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.