相当于 Windows 的 gettimeday() [英] Equivalent of gettimeday() for Windows

查看:34
本文介绍了相当于 Windows 的 gettimeday()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道 Windows 环境中 gettimeofday() 函数的等效函数?我正在比较 Linux 和 Windows 中的代码执行时间.我正在使用 MS Visual Studio 2010,它一直说,标识符gettimeofday"未定义.

Does anyone know an equivalent function of the gettimeofday() function in Windows environment? I am comparing a code execution time in Linux vs Windows. I am using MS Visual Studio 2010 and it keeps saying, identifier "gettimeofday" is undefined.

推荐答案

GetLocalTime() 用于系统时区的时间,GetSystemTime() 用于 UTC.那些以 SYSTEMTIME 结构返回日期/时间,在那里它被解析为年、月等.如果你想要一个自纪元以来的秒数,请使用 SystemTimeToFileTime()GetSystemTimeAsFileTime().FILETIME 是一个 64 位值,自 UTC 时间 1601 年 1 月 1 日起间隔为 100ns.

GetLocalTime() for the time in the system timezone, GetSystemTime() for UTC. Those return the date/time in a SYSTEMTIME structure, where it's parsed into year, month, etc. If you want a seconds-since-epoch time, use SystemTimeToFileTime() or GetSystemTimeAsFileTime(). The FILETIME is a 64-bit value with the number of 100ns intervals since Jan 1, 1601 UTC.

对于间隔时间,使用GetTickCount().它返回自启动以来的毫秒数.

For interval taking, use GetTickCount(). It returns milliseconds since startup.

要以最佳分辨率(仅受硬件限制)获取间隔,请使用 QueryPerformanceCounter().

For taking intervals with the best possible resolution (limited by hardware only), use QueryPerformanceCounter().

这篇关于相当于 Windows 的 gettimeday()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆