Results 1 to 6 of 6

Thread: What is the easiest way to test how much time does an operatioin take?

  1. #1
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default What is the easiest way to test how much time does an operatioin take?

    I want to know how much time does my function take,so that I can compare and choose the better one.
    Is there an easy way to do this?I don't want unit test thing,that seems like a bit overkill.
    It's not the goodbye that hurts,but the flashback that follow.

  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: What is the easiest way to test how much time does an operatioin take?

    It depends what reliability of such measurement you require.
    The easiest way is:
    Qt Code:
    1. t.start();
    2. functionCall();
    3. qDebug() << t.elapsed() << "ms";
    To copy to clipboard, switch view to plain text mode 
    but it is completely unreliable, especially if your function is short. Much better is to use QBENCHMARK from QtTestLib (I don't think it is an overkill).
    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. The following 2 users say thank you to wysota for this useful post:

    MorrisLiang (12th June 2010), Zlatomir (12th June 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is the easiest way to test how much time does an operatioin take?

    I tried QBENCHMARK today,but with no luck.
    Qt Code:
    1. public slots:
    2. void testUpdateContents()
    3. {
    4. QBENCHMARK
    5. {
    6. updateContents();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    In one of my class, there's a slot called testUpdateContents().It's connected to a QPushButton's clicked() SIGNAL.It complied without any error.
    But when I clicked that button,I got "Segmentation fault".
    The attachment shows where's the line of code causing the problem.
    Attached Images Attached Images
    It's not the goodbye that hurts,but the flashback that follow.

  5. #4
    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: What is the easiest way to test how much time does an operatioin take?

    What does updateContents() do? By the way, QBENCHMARK should be used in tests, not in regular apps.
    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.


  6. #5
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is the easiest way to test how much time does an operatioin take?

    Quote Originally Posted by wysota View Post
    What does updateContents() do? By the way, QBENCHMARK should be used in tests, not in regular apps.
    updateContents() is just a normal function which updates an list of QWidgets.
    Ok,I read the tutorial again,finally knows how to use it.Thanks~
    It's not the goodbye that hurts,but the flashback that follow.

  7. #6
    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: What is the easiest way to test how much time does an operatioin take?

    Quote Originally Posted by MorrisLiang View Post
    updateContents() is just a normal function which updates an list of QWidgets.
    If what the function does is that it schedules some events (i.e. by calling update() on widgets) then measuring the time it takes to finish the updateContents() function doesn't yield any practical value as most work is done already after that function returns (in the event loop).
    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. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  2. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 09:10
  3. Easiest way to detect right mousebutton?
    By Teuniz in forum Qt Programming
    Replies: 7
    Last Post: 21st May 2007, 08:29
  4. Easiest way to display icons in a table
    By ghorwin in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2007, 13:09
  5. Replies: 2
    Last Post: 10th February 2006, 12:57

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.