Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

performance - Multicore and thread aware .Net stopwatch?

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

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.

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?

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...