How to calculate the CPU execution time

code - execution time of the C program

c time (9)

(All the answers here are missing if your system administrator changes the system time or your time zone has different winter and summer times. Therefore ...)

Under Linux: It is not affected if the system administrator changes the time, or if you live in a country with winter time different from summer time, etc.


I have a C program that is supposed to be executed in parallel on several processors. I need to be able to record the execution time (which could be anywhere from 1 second to several minutes). I've been looking for answers but all seem to suggest using the function which then calculates the number of bars the program took divided by the value.

I am not sure how the value is calculated?

In Java I just take the current time in milliseconds before and after the execution.

Is there a similar thing in C? I've looked at it, but I can't find a way to achieve anything better than a second solution.

I am also aware that a profiler would be an option, but I am looking to implement a timer myself.

Many Thanks