Results 1 to 6 of 6

Thread: How to check the rapidity of execution of a method during runtime ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default How to check the rapidity of execution of a method during runtime ?

    Hi everybody.

    I have an application with some function, some of them are identical but coded differently. I want to test each of these identical functions in order to know which one is the fastest during runtime.

    If I add some specific code in my applycation for the test, it will probably interfere with the results no ? Does someone know a way to process such tests, what should I take care during the developpment of the test architecture ?

    Thanks in advance.

  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to check the rapidity of execution of a method during runtime ?

    You are looking for a way to profile your code. Take a look at, for example gprof (which comes with gcc).

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: How to check the rapidity of execution of a method during runtime ?

    I am using VC++ 6.0 so it won't be possible to use gprof. Can you tell me more about code profiling ?

    What I want to know is the time spended in some function in ordre to try, test and validate some kind of implementation for many similar functions.

  4. #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: How to check the rapidity of execution of a method during runtime ?

    Then use a profiler suited for MSVC There probably is one. You also probably have to pay for it, but I guess you're ready for that if you decided to use MSVC.

    Of course you can make pseudo-tests using your code directly. Just use some way to measure time differences (for example using time() or clock()).

  5. #5
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to check the rapidity of execution of a method during runtime ?

    At work we used to use intel's v-tune for profiling purposes with visual c++ applications.

    However, if you are only interested in how long a certain function runs you might as well just take the start and end time and substract start from end to get the runtime, for instance like this:

    Qt Code:
    1. #include <iostream>
    2. #include <ctime>
    3.  
    4. using namespace std;
    5.  
    6. void myFunction()
    7. {
    8. int j = 0;
    9.  
    10. for (int i = 0; i < 1000000; ++i)
    11. {
    12. ++j;
    13. }
    14. }
    15.  
    16. void main(int argc, char** argv)
    17. {
    18. // start benchmarking
    19. double truntime=0.0, tstart;
    20. tstart = clock();
    21.  
    22. myFunction();
    23.  
    24. // end benchmarking
    25. truntime += clock() - tstart;
    26.  
    27. // rescale to seconds
    28. truntime /= CLOCKS_PER_SEC;
    29.  
    30. cout << "Runtime was: " << truntime << " seconds." << endl;
    31.  
    32. return 0;
    33. }
    To copy to clipboard, switch view to plain text mode 

    edit: wysota beat me

  6. #6
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: How to check the rapidity of execution of a method during runtime ?

    Ok, I know now what profiling is and found were to enable this feature in MSVC. I think it will be enough for my need.

    Thanks to all.

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.