hello again my question if it is possible to print microsencods using TimesSpan in C#.
i have the next example:
DateTime startTime = DateTime.Now;
..../some code
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startTime);
Label3.Text=(totalTimeTaken.Milliseconds).ToString();
this code allows me to display in milliseconds but i need to display Microseconds is there a way to change it to Microseconds or do I have to use something else?
have to edit my question:
my goal is to measure the time that is spent between the 2 DateTime, since it is very few lines of code the milliseconds just wont cut it, thats the reason i need the microseconds.
The highest resolution you will find will be via the Stopwatch class. If your CPU supports a high resolution timer, the Stopwatch class will use it. You can check this via the
IsHighResolutionand/orFrequencyproperties.This is the class you should be using for performance measurements, not
DateTime.EDIT: I just learned something new about DateTime. From the docs…
However, the resolution of
DateTime.Nowis still about 15ms, so it won’t work (which makes the documentation misleading at best…) Use the Stopwatch.