mata mata - 2 months ago 5x
C++ Question

How can I measure the execution time of one thread?

I'm running a couple of threads in parallel. And I want to measure the time it takes to execute one thread and the time it takes to execute the whole program. I'm using VC++, on Windows 7.

I tried to measure it while debugging but then I saw this question: Improving performance using parallelism in c++ and in the answer given by Schnien it says:

Debugging of multiple threads is somehow "special" - when your Debugger halts at a breakpoint, the other threads will not be stopped - they will go on

Is this true ? And if yes how can I otherwise measure the time



That statement is indeed true, only the thread that hits a breakpoint will be paused.

However to measure execution times you do not have to use debugging at all. More information on measuring execution time can be found on the below question:

Measure execution time in C (on Windows)

What you would want to do is measure the time inside the threads' functions (by subtracting the time at the beginning and at the end of the functions). You can do the same with the program, you can use thread.join to make sure all the threads executions end before measuring the time one last time.