C# benchmarking: How accurate is Process.TotalProcessorTime -


i'm trying measure execution time of processes within c#. code i'm using this:

    private static double timeprocess(string name, string workingdirectory, string arguments)     {         process process = new process();         process.startinfo.workingdirectory = workingdirectory;         process.startinfo.filename = name;         process.startinfo.windowstyle = processwindowstyle.hidden;         process.startinfo.createnowindow = true;         process.startinfo.arguments = arguments;          process.start();         process.waitforexit();          return process.totalprocessortime.totalmilliseconds;     } 

i aware usual way of benchmarking instantiate stopwatch , use measure elapsed time, however, wondering if stopwatch appropriate in case, since subject influence of scheduling example. approach guarantee measure time process spends in execution.

my 2 questions:

  1. am wrong in assuming stopwatch less accurate/an inferior choice in case?
  2. how precise process.totalprocessortime? can see calls kernel32 method "getprocesstimes", having hard time finding information how method works. meanwhile, there plenty information available "queryperformancecounter" method stopwatch uses.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -