In my application I am executing a new .NET Thread and within that thread I am acomplishing a task.
I am using Stopwatch to measure the execution time but Stopwatch measures the execution time of all threads of OS (nut just the execution time for my thread). I want a way to measure just the time that my created thread takes to execute its own instructions.
Is there such a way of measuring in .NET?
There are two ways to measure elapsed execution time in Java either by using System. currentTimeinMillis()or by using System. nanoTime(). These two methods can be used to measure elapsed or execution time between two method calls or events in Java.
To calculate time taken by a process, we can use clock() function which is available time.
The difference between the end time and start time is the execution time. Get the execution time by subtracting the start time from the end time.
measure execution time of a program. Using time() function in C & C++. time() : time() function returns the time since the Epoch(jan 1 1970) in seconds. Prototype / Syntax : time_t time(time_t *tloc);
There is no way to do this in managed code only, but you can PInvoke QueryThreadCycleTime or GetThreadTimes. There is one thing to keep in mind - there is no requirement that there must be a one to one relationship between managed and native threads but as far as I know this is the way it currently works. Using Stopwatch
you will always get the elapsed wall clock time including time when your thread was suspended.
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