Measuring time in C
问题 I'm trying to measure some activity in C (Matrix multiplying) and noticed that I should do something like this: clock_t start = clock(); sleep(3); clock_t end = clock(); double elapsed_time = (end - start)/(double)CLOCKS_PER_SEC; printf("Elapsed time: %.2f.\n", elapsed_time); The output is: Elapsed time: 0.00. Why is this happening? 回答1: clock estimates the CPU time used by your program; that's the time the CPU has been busy executing instructions belonging to your program. sleep doesn't