0

How can I check the evaluation processing time of my application. For example how many time it needs to do A, B, C, A+C, B+C, ...

user1764961
  • 673
  • 7
  • 21
Mike
  • 563
  • 5
  • 15
  • 32
  • Keep a set of counter variables and increment them whenever you do an operation you want to track? – millimoose Sep 18 '13 at 15:00
  • Are you actually looking to measure the time of the whole application, a part of the application, or do you want to measure how many times it does a certain thing (function or instruction)? – Mats Petersson Sep 18 '13 at 15:02
  • @Mats Petersson as you can see from my question I want to measure time for every combination of operations I am interested in. The whole working time is just combination off everything. – Mike Sep 18 '13 at 15:07
  • And what is A, B and C? Instructions or functions? – Mats Petersson Sep 18 '13 at 15:13
  • Parts of program - for example let A be the time that program spends to load a file, B - the time that program spends to apply some algorithm on the loaded file, C - the time to execute – Mike Sep 18 '13 at 15:14

3 Answers3

0
  1. You could use gettimeofday() and use the timersub() function to get the difference.

  2. You could use clock() and subtract the two times. Remember to #include .

-Referenced from:

How to subtract two gettimeofday instances?

http://www.cplusplus.com/forum/unices/50561/

What is the best, most accurate timer in C++?

EDIT: Another option is chrono i/o. Gives very high precision. http://howardhinnant.github.io/duration_io/chrono_io.html

Community
  • 1
  • 1
philhan
  • 590
  • 1
  • 6
  • 19
0

If you use linux. Command 'time' can help you:

$time ./a.out 

real    0m0.137s
user    0m0.001s
sys     0m0.001s
0

Use QueryPerformanceCounter().

LARGE_INTEGER s, e, f;

QueryPerformanceFrequency( &f );
QueryPerformanceCounter( &s );

// TO DO: add your code here

QueryPerformanceCounter( &e );


const __int64 durationMilliseconds = ( e.QuadPart - s.QuadPart ) * 1000 / f.QuadPart;
user1764961
  • 673
  • 7
  • 21