Program Timing

How can I time how long it takes for my program to run?


Date Command

A simple way to get the `wallclock' timing of a program is to use the dat command before and after the program and compare the diffference. Suppose the executable in question is called myprog and is in the current dirctory then doing


date ; ./myprog ; date

Will first run the date command, then run the code and finally run the date command again. The output of the date command will take the form


Tue Nov 21 10:11:41 GMT 2000

Time Command

For more detailed information you can use the time command by doing


time ./myprog

The output from time takes the form


0.000u 0.000s 0:00.01 0.0%      0+0k 0+0io 84pf+0w

where

0.000u CPU time spent in user space
0.000s CPU time spent in system space
0:00.01 the wallclock time
0.0% the percentage of execution time spent idle (a process will idle if waiting for user input, for example)
0+0k the shared text size (lhs of '+') and the data size (rhs of'+')
0+0io the amount of data input (lhs of '+') and output (rhs of '+')
84pf+0w the number of page faults and the number of page swaps
Please contact us with feedback and comments about this page. Last updated on 02 Apr 2022 21:54.