Timer is important for measuring speed-ups or elapsed time for custom algorithms.

We used to import <ctime> and measure time with:

However, clock() measures CPU time, not actual time elapsed (which may be much greater) according to this StackOverFlow.

Hence, here provides my code snippets to measure execution time in C++ as a DebugTimer Class.

It also supports using an average window to measure the average time within AVERAGE_WINDOW_SIZE.

It’s a static class, so it’s very easy to use, and it supports multiple threads:

That’s it!


Another way to meaasure time is to use:

I personally don’t like this simple expression, but it also works well.