in short 1): if the stopwatch instance is used on a thread for which the processor affinity is not set to a single logical core, the stopwatch measurements are unreliable (they will report negative times, unbelieavable times like 100 times the amount).
2) from my personal experience with this class, i tried to work arround this (setting processor afinity is clearly what you dont want to deal with) using the StopWatch.GetTimeStamp() method which is supposed give a high resolution timer if the underlying system supports it. this amount of ticks can be converted into ms like that:
var start = StopWatch.GetTimeStamp();
var end = StopWatch.GetTimeStamp();
long elapsedms = ((end - start) / StopWatch.Frequency;
On the plus side, this static method might be lighter and lower level than the instance usage.
Hello everyone,
Just a few notes on the current stopwatch implementation of microsoft, it has a few issues on multicore systems : msdn.microsoft. com/en- us/library/ system. diagnostics. stopwatch. aspx)
(noted in the reference page http://
in short 1): if the stopwatch instance is used on a thread for which the processor affinity is not set to a single logical core, the stopwatch measurements are unreliable (they will report negative times, unbelieavable times like 100 times the amount).
2) from my personal experience with this class, i tried to work arround this (setting processor afinity is clearly what you dont want to deal with) using the StopWatch. GetTimeStamp( ) method which is supposed give a high resolution timer if the underlying system supports it. this amount of ticks can be converted into ms like that:
var start = StopWatch. GetTimeStamp( ); GetTimeStamp( ); Frequency;
var end = StopWatch.
long elapsedms = ((end - start) / StopWatch.
On the plus side, this static method might be lighter and lower level than the instance usage.
Btw, thanks for your hard work.