.net - 多核和线程感知 .Net 秒表?

标签 .net performance stopwatch

众所周知秒表 在将在所有内核上运行的多线程异步应用程序中可能存在问题。

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 内核一致的值?

如果不可能使秒表(QueryPerformanceCounter)多核安全,那么在内核间获得良好时间戳的下一个最佳方法是什么? 日期时间.UtcNow.Ticks Environment.TickCount ?还有其他柜台吗?

我确实需要比 DateTime.UtcNow.Ticks 可以提供的更好的分辨率。 (10-15ms)

最佳答案

我自己搜索过这个特定问题的答案,我见过的最好的是 DateTime.UtcNow。似乎没有Windows暴露的高分辨率和可靠 柜台(我已经用谷歌搜索了很长时间,但仍然没有遇到任何)。

关于.net - 多核和线程感知 .Net 秒表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9283368/

相关文章:

.net - 随机 "could not establish secure channel for SSL/TLS"错误

.net - 如何阻止 winform 设计器将自定义控件的版本放入 .resx 文件中?

c# - 修改 XmlDocument 时出现 InvalidOperationException

c# - 任务中的秒表似乎在所有任务中都是可加的,只想测量任务间隔

java - 是否已经有一个适用于 android 的 StopWatch 类,为什么我的实现不起作用?

c# - 在不同屏幕上显示 C# WinForm

jquery - AJAX 调用可能导致站点内存泄漏

java - 使 MySQL 查询更快

Java - 堆栈类找不到内存泄漏

javascript - angularjs计算开始时间和当前时间的时间差