问题描述
我需要创建一个函数,该函数在C#或C ++中以毫秒为单位测量时间.我如何使用Visual Studio 2008做到这一点?
I need to create a function that measures time in microseconds in C# or C++. How can I do that using Visual Studio 2008?
推荐答案
您可以尝试以下操作,但是请记住,最接近的时间约为15到20毫秒(+/-几毫秒,具体取决于您的硬件):
You might try the following, but remember that the closest you''d get to would be something like 15 to 20 milliseconds (+/- a few milliseconds, depending on your hardware):
-
QueryPerformanceCounter()
:此函数将返回非常精确的时间计数,但是由于Windows不是实时操作系统,因此有时该计数没有意义.请注意,在某些情况下,计数甚至可能会倒退! - 多媒体计时器功能:我从没使用过这些功能,只听说过它们.我知道它们的工作方式比
QueryPerformanceCounter()
可靠一些,但是它们也有局限性.
QueryPerformanceCounter()
: This function will return a time count that''s very precise, but because Windows isn''t a real-time operating system, sometimes the counts won''t make sense. I understand that the count can even seem to go backwards in some situations!- Multimedia Timer functions: I''ve never used these, only heard about them. I understand that they work somewhat more reliably than
QueryPerformanceCounter()
, but they too have limitations.
C#或C ++.如何使用Visual Studio 2008做到这一点?
C# or C++. How can I do that using Visual Studio 2008?
Visual Studio的版本(或任何其他IDE)或尝试使用此语言的编程语言均无关紧要.
我之所以这样说,是因为Windows甚至无法提供毫秒的精度.微秒是毫秒精度的千倍倍,因此您需要放弃在Windows上尝试此操作.
而是选择一个RTOS.
The version of visual studio (or any other IDE), or the programming language that you may use to attempt this is irrelevant.
I say it because Windows can''t even give you the precision of milliseconds. Microseconds is a thousand times the precision of milliseconds, so you need to give up trying this on Windows.
Choose an RTOS instead.
这篇关于测量时间(以微秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!