Computing CPU time in C++ on Windows

后端 未结 5 905
無奈伤痛
無奈伤痛 2021-02-03 14:50

Is there any way in C++ to calculate how long does it take to run a given program or routine in CPU time?

I work with Visual Studio 2008 running on Wind

5条回答
  •  醉酒成梦
    2021-02-03 15:07

    The __rdtscp intrinsic will give you the time in CPU cycles with some caveats. Here's the MSDN article

    It depends really what you want to measure. For better results take the average of a few million (if not billion) iterations.

提交回复
热议问题