对具有高分辨率和可移植性的代码段进行计时的最佳方式是什么?
/* Time from here */
ProcessIntenseFunction();
/* to here. */
printf("Time taken %d seconds %d milliseconds", sec, msec);
有没有具有跨平台解决方案的标准库?
对具有高分辨率和可移植性的代码段进行计时的最佳方式是什么?
/* Time from here */
ProcessIntenseFunction();
/* to here. */
printf("Time taken %d seconds %d milliseconds", sec, msec);
有没有具有跨平台解决方案的标准库?
我认为这应该奏效:
#include <time.h>
clock_t start = clock(), diff;
ProcessIntenseFunction();
diff = clock() - start;
int msec = diff * 1000 / CLOCKS_PER_SEC;
printf("Time taken %d seconds %d milliseconds", msec/1000, msec%1000);