Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I measure the time of a thread in c#? [duplicate]

I want to measure the time that a C# routine needs. Because there are many other threads I only want to count the time of this one thread. In Java I can use getCurrentThreadCpuTime.

How can I do it?

like image 314
Horcrux7 Avatar asked Apr 24 '13 13:04

Horcrux7


2 Answers

You should look into PerformanceCounters. They are quite complex and can be a bit of a pain to set up, but are robust in what they offer for metrics. A couple of things that might help:

Performance counters and threading

http://blogs.msdn.com/b/adamhems/archive/2008/12/04/using-custom-performance-counters-to-measure-multi-threaded-operation-durations.aspx

like image 115
AJ. Avatar answered Sep 28 '22 04:09

AJ.


You can't. You cannot measure the accumulated time ON THE CPU for a particular thread. The most accurate thing you could do would be to spin off a separate process for each of your tasks, and then measure the CPU time for the process (which actually can be done in .Net)... but that's overkill.

If you need help on how to do that, you should ask another question specifically for that.

like image 37
eMi Avatar answered Sep 28 '22 03:09

eMi