c# - What, if any, is the resource penalty for using System.Diagnostics.Stopwatch? -


For example

  foo () // Some actions bound by an external resource. DB, I / O, whichever is it  

versus

  var clock = new stopwatch (); Watch.Start (); Foo () var time = clock. Elapsed milliseconds clock Stop (); I believe that the stopwatch is built on top of the query performance control, so the results of each call are in the kernel. Infection. If foo () is very short, then the QPC overhead will dwarf it. 

If you are using a stopwatch to measure small tasks, you should run many times (like thousands) of foo, and use the stopwatch around to get the average time for the whole batch work Divide total time by the number of runs.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -