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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With