0

I have a multi-process program written in C, where the parent forks a number of children, and I need to calculate its running time, and compare it with the running time of a multi-threaded program which does the same task as that by the multi-process one.

Except using time.h's clock function (which reports CPU time, thus may report more time in a multi-threaded program if no. of threads is high), what else can I use to calculate both programs' running time for comparison purposes ?

I am currently using time ./a.out to calculate their running time.

Jarvis
  • 8,494
  • 3
  • 27
  • 58
  • clock_gettime may work for this purpose: http://stackoverflow.com/questions/2962785/c-using-clock-to-measure-time-in-multi-threaded-programs – Robert Prévost Sep 03 '16 at 03:29
  • What is your definition of "running time"? Do you mean the wall-clock time it takes between the time the first child process is initiated and the last child process terminates? do you mean the aggregate wall-clock time used by all child processes? (e.g. if two processes took 5 seconds to complete, the aggregate wall-clock time would be 10 seconds) Or do you mean the amount of cpu time accumulated by all the child processes? – J Earls Sep 03 '16 at 06:06
  • I mean the wall-clock time. – Jarvis Sep 03 '16 at 06:16

1 Answers1

0

Just use gettimeofday() from the time library on the main thread and it should give you its elapsed time.

If you run it on a thread it will only reply back with that particular threads elapsed time.

Null Byte
  • 48
  • 3