How can I get the execution time of a program in milliseconds in C?

后端 未结 6 1021
清酒与你
清酒与你 2020-12-30 09:28

Currently I\'m getting the execution wall time of my program in seconds by calling:

time_t startTime = time(NULL);
//section of code
time_t         


        
6条回答
  •  甜味超标
    2020-12-30 10:20

    On Windows, use QueryPerformanceCounter and the associated QueryPerformanceFrequency. They don't give you a time that is translatable to calendar time, so if you need that then ask for the time using a CRT API and then immediately use QueryPerformanceCounter. You can then do some simple addition/subtraction to calculate the calendar time, with some error due to the time it takes to execute the API's consecutively. Hey, it's a PC, what did you expect???

提交回复
热议问题