Obviously, I can do DateTime.Now.After - DateTime.Now.Before , but there must be something more complicated.
DateTime.Now.After
DateTime.Now.Before
Any advice appreciated.
The System.Environment.TickCount and System.Diagnostics.Stopwatch class are two that work well for finer resolution and easier use.
See also:
I would definitely advise you to take a look at System.Diagnostics.Stopwatch
System.Diagnostics.Stopwatch
And when I looked around more about the stopwatch, I found this site;
Beware of the stopwatch
Another possibility was mentioned there.
Process.TotalProcessorTime
Use profiler
However, your approach will work, but if you are looking for more complex approaches. I would suggest using C # Profiler .
The benefits they have:
There are many open-source available .
Tickcount is good, but I suggest running it 100 or 1000 times and calculating the average. This not only makes it more measurable - in the case of really fast / short functions, but helps to cope with some one-time effects caused by overhead.