How to measure the time that a piece of code takes to execute?
问题 Suppose I want to measure the time that a certain piece of code takes. For that I would normally do something like this clock_t startTime = clock(); //do stuff //do stuff //do stuff //do stuff float secsElapsed = (float)(clock() - startTime)/CLOCKS_PER_SEC; What if the program is multithreaded and context switches occur within the part which I want to measure? How would I measure the time that my code takes to execute excluding time spent on other threads? Even if there are tools that do it,