clock function in C++ with threads

If more than one core is available, and you are running multiple threads, then potentially multiple threads are executing at the same time on different cores. Since clock() measures processor time, it may advance faster than wallclock time, because multiple threads are advancing it simultaneously.

Just as the example given in the documentation – it shows two threads created, and the clock() value reported is almost double the wallclock time reported.

Leave a Comment