简体   繁体   中英

What is the best way to calculate the running time of a multi-process program?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM