Click here to Skip to main content
11,415,046 members (76,250 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
how to find my logic execution time in c#.net?
Posted 16-Nov-12 2:40am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi

You will have to use the timer, Start it before the logic and stop it after the logic. .NET has an inbuilt timer.

Jacques
  Permalink  
Comments
OriginalGriff at 16-Nov-12 7:50am
   
This is not a good solution - both the Timer classes have poor resolution and are not intended for accurate measurement. Use the Stopwatch class instead.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Look at the Stopwatch class[^] - it's easy to use and provides accurate timing.
This Tip shows it in use to measure the execution time of various different ways of counting lines in a string: Counting lines in a string[^]
  Permalink  
Comments
Jacques Loubser at 16-Nov-12 7:56am
   
If you are after accuracy, use the Direct X timer. It is a single timer that is accurate to 1/1000000000th of a second. But then you will have to package Direct X with your distribution...
OriginalGriff at 16-Nov-12 8:08am
   
Um. Probably not that accurate in reality. It uses the system performance query and is as accurate as the hardware on any specific computer lets it be. Just because it reports in nanoseconds, does not mean it is accurate to the nanosecond!
In fact, it can be less accurate than a System.Trheading.Timer on systems where the processor speed can be varied according to load...
Jacques Loubser at 16-Nov-12 8:14am
   
This timer is used for the graphics timing, but I agree, you can't be more accurate than the hardware permits.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,200
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web04 | 2.8.150427.4 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100