以毫秒precision Windows系统的时间 [英] Windows system time with millisecond precision

查看:195
本文介绍了以毫秒precision Windows系统的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://stackoverflow.com/questions/3138275/using-ansi-c-on-windows-platform-can-i-get-time-of-system-upto-milliseconds-accur">Related我的previous问题,但与C#,我需要precise系​​统时间,包括毫秒。

Related to my previous question, but with C#, I need the precise system time including milliseconds.

C#时间函数的精度可达10〜15毫秒,但不完全是1毫秒。

C# time function has accuracy up to 10 to 15 milliseconds, but not exactly 1 millisecond.

同样是队列性能计数器的情况。是否有任何其他的方式来获得精确度可达确切毫秒?

The same is the case with Queue performance counter. Is there any other way to get accuracy up to exact millisecond?

推荐答案

Windows不希望通过更新系统时钟每秒1000次,浪费电,所以默认是只更新它每秒60-100次。如果设置了多媒体定时器1毫秒,你可以从时钟1ms的分辨率,但不推荐。

Windows does not want to waste electricity by updating the system clock 1000 times per second, so the default is to only update it 60-100 times per second. If you set the multimedia timer to 1ms, you can get 1ms resolution from the clock, but that's not recommended.

要更多地讨论节约的电费,会发生什么,当CPU处于空闲状态一段时间,它可以进入一个非常低功耗状态。每当被中断(例如,为了增加时钟滴答),它必须离开其本身的低功耗状态,并使用大量电力的整个CPU服务的中断供电。换言之,附加的动力不递增时钟节拍,它是在保持了CPU清醒做到这一点。

To elaborate more on the electricity savings, what happens when the CPU is idle for a period of time is that it can go into a very-low-power state. Whenever it gets interrupted (e.g. to increment the clock ticks) it has to leave its very-low-power state and use lots of electricity to power the whole CPU to service that interrupt. In other words, the additional power isn't in incrementing the clock ticks, it's in keeping the CPU awake to do it.

由于我的笔记本电脑使用10W待机时的时钟频率为60Hz 11W时,它的1000赫兹,而我获得300分钟的续航时间,即较慢的时钟是给我的电池续航时间约30多分钟!

Since my laptop uses 10W at idle when the clock frequency is 60Hz and 11W when it's 1000Hz, and I get 300 minutes of battery life, that slower clock is giving me almost 30 extra minutes of battery life!

这篇关于以毫秒precision Windows系统的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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