There are often cases that you need to measure the execution time of your program. Working in Windows or Linux one gets used to the "time" system utility, which allows one to measure both system and kernel time of any executable just by preceding it with complete parameter set in the command line (for instance "time du").

Pity, there is no such a handy routine in (usual) Windows installation and the "timeit.exe" solution which one might find on many Internet forums does not seem to work in all cases (at least it does not in my case of Windows 7 Ultimate). There is, however, a nice workaround for this problem, provided you want to measure the execution time of one or few runs, by using Process Explorer from Sysinternals toolset by Mark Russinovich. This solution, however, does not help in case you need to perform multiple performance run tests of your software. Please, refer to Visual Studio Profiler in this case.

  1. So, first you need to download the latest version of Process Explorer from here:
    http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
       
  2. Once you downloaded it and agreed to the user agreement you can see the main screen:

  3. You first should add the parameters you'd like to get from your program to the list of visible columns. For this purpose go to View and choose Select Columns

  4. Go to the "Process Performance" tab



    and select the counters you'd like to see in the general process list. In order to get the total execution time you'll need to tick the "CPU Time" option:



    Click OK to go back to the main screen and you will see the new column CPU Time to the very right of the process table. The order of columns can be easily changed just clicking on the column caption and dragging it to the desired position.

    Note: You might need to enlarge your Process Explorer window to see the new column.
  5. Now you are almost ready to capture the information you need. However if you now start your process and immediately switch back to the Process Explorer, find it in the list of running processes and wait until it terminates you can read the total execution time in the CPU Time column. It works fine in many cases, but you may encounter two types of problems:
    1. If the process you start just runs shortly you may miss your process, for it is already finished by the time you have switched back to Process Explorer and found it in the list.
    2. Even if you managed to get your process, the information about total runtime is quickly purged from the process list.
  6. To solve these problems let us increase the time process is shown in the list after it has terminated. For this purpose go to Options -> Difference Highlight Duration and set the duration to 9 seconds:



    Now the process will remain in the list for 9 seconds after its termination.



    That should be enough to write down its execution time. Now just start your program and read the execution time after its termination. You can easily identify the process which terminated shortly by the red background highlighting (on the screenshot you can see the "pan.exe", the compiled verifier from Spin).