用TC2.0编程时怎么获得毫秒级的时间

来源:百度知道 编辑:UC知道 时间:2024/05/04 03:57:38
想用TC获得毫秒级的时间,在网上找了很久也没找到.以前用过struct time结构体,但只能精确到秒.在CSDN里面找到一个struct timeval结构体,好象能精确到毫秒,但TC里好象找不到这个结构体.大概就这么多问题了,有人知道的话请说一下吧,谢谢了.
请问底楼的2位朋友,没有直接返回毫秒级时间的函数吗?

好可以解决的啊。
楼主应是能够写显示时间的语句了,我们可以做个循环体,for (long int i=0;i<10000000000;i++;);
可以看它执行完用了多少秒,这样可换算出你机器执行一次循环用的豪秒数,这样你要几个豪秒就循环几次,可以用这样的循环来控制下一条语句的执行时间啦。

而如果你是想知道你程序出结果时用的毫秒数,那不妨让你的计算程序重复计算,很多次重复,直到用了1秒以上,只取最后一次的时间,减去重复前的时间,除以你的重复次数,就可换算出相应的豪秒数来啦。

#include <windows.h> //如果有的话
GetTickCount()函数将返回DWOD类型的毫秒级时间。:
For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at 0 on boot and then counts up from there.

For Debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted. This allows code that uses GetTickCount to be easily tested for correct overflow handling.

DWORD GetTickCount(void);
Return Values
The number of milliseconds indicates success.

Remarks
The resolution of the system timer is based on the OEM's setting. Check with the