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:
- am wrong in assuming stopwatch less accurate/an inferior choice in case?
- 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
Post a Comment