多核和线程感知净秒表? [英] Multicore and thread aware .Net stopwatch?

查看:119
本文介绍了多核和线程感知净秒表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家都知道在秒表可能将在所有内核上运行的问题在一个多线程的异步应用程序。

As we all know the stopwatch might have issues in a multi-threaded async application that will be running on all cores.

在多处理器计算机,无所谓哪个处理器线程运行。因为在BIOS或硬件抽象层(HAL)的bug但是,你可以在不同的处理器不同的时序结果。要为指定线程处理器的亲和力,使用ProcessThread.ProcessorAffinity方法。

On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread.ProcessorAffinity method.

有没有办法,我得到一些可靠的滴答/时间戳一样,具有很高的分辨率/精度和值是多个CPU内核一致?

Are there any way for me to get some reliable tick/timestamp like values that has high resolution/accuracy as well is consistent across cpu cores?

如果无法使秒表(QueryPerformanceCounter的)多核安全,什么是让整个内核一个很好的时间戳下一个最好的方法是什么? DateTime.UtcNow.Ticks Environment.TickCount ?任何其他柜台​​?

If not possible to make the stopwatch(QueryPerformanceCounter) multi-core safe, what is the next best way to get a good timestamp across cores? DateTime.UtcNow.Ticks or Environment.TickCount? Any other counters?

我需要比DateTime.UtcNow.Ticks可以提供更好的解决方案。 (10-15ms)

I do need better resolution than what DateTime.UtcNow.Ticks can provide. (10-15ms)

推荐答案

我寻觅的答案,这一特定问题我自己和我所见过的最好的是DateTime.UtcNow。这似乎是没有的Windows暴露高分辨率和可靠计数器(我用Google搜索的一个是年龄,还没有碰到过的话)。

I have searched for an answer to this specific problem myself and the best that I have seen is DateTime.UtcNow. It would seem that there is no Windows exposed high resolution and reliable counter (I have googled for one for ages and still haven't come across any).

这篇关于多核和线程感知净秒表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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