I’m using something like this to count how long does it takes my program from start to finish:
int main(){
clock_t startClock = clock();
.... // many codes
clock_t endClock = clock();
printf("%ld", (endClock - startClock) / CLOCKS_PER_SEC);
}
And my question is, since there are multiple process running at the same time, say if for x amount of time my process is in idle, durning that time will clock tick within my program?
So basically my concern is, say there’s 1000 clock cycle passed by, but my process only uses 500 of them, will I get 500 or 1000 from (endClock - startClock)?
Thanks.
clockon POSIX measures cpu time, but it usually has extremely poor resolution. Instead, modern programs should useclock_gettimewith theCLOCK_PROCESS_CPUTIME_IDclock-id. This will give up to nanosecond-resolution results, and usually it’s really just about that good.