I need a clock like Stopwatch.GetTimestamp()
that
DateTime.Now
is)Stopwatch
seems to fail to provide the last of these properties:
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.
To enable real concurrency, for obvious reasons I cannot pin all threads to a single processor.
Any alternative I can use in .net? Or is the above warning outdated / restricted to some rare models (my production environment is unlikely to house)?
Edit:
Here's my main concern: I don't mind values being off by one (e.g. millisecond) or so on different processors, but they need to be always be more or less the same no matter what processor they are retrieved from.
MS actually has an in-depth article on the counters underlying Stopwatch
. Acquiring high-resolution time stamps
A relevant excerpt:
In general, the performance counter results are consistent across all processors in multi-core and multi-processor systems, even when measured on different threads or processes. Here are some exceptions to this rule: