垃圾收集器是在一个单独的进程中启动的吗?
例如:
如果我们尝试测量一些代码所花费的处理时间,并且在此期间垃圾收集器开始收集,它将在新进程或同一进程中启动吗?
它是否像以下一样工作?
//Code (Process 1)
--> Garbage Collector Run (Process 1)
//Code (Process 1)
Run Code Online (Sandbox Code Playgroud)
或者像这样?
//Code (Process 1)
--> Garbage Collector Run (Process 2)
//Code (Process 1)
Run Code Online (Sandbox Code Playgroud)我已经在某处读过这个答案,但我完全不明白:
我理解Windows使用curTimeAdjustment(156001 + - N)的值每curTimeIncrement(156001 100纳秒)递增时钟.但是当使用GetSystemTime读取时钟时,例程会在156001纳秒*100的时间间隔内插入以产生指示的精度吗?
有人可以试着向我解释一下吗?
是什么curTimeIncrement
,curTimeAdjustment
以及Windows如何做到这一点?
这对获得准确时间有什么影响?
这是真的只适用于Windows 7或其他操作系统Win8,Linux等等吗?
我尝试捕获函数的确切执行时间
Stopwatch regularSW = new Stopwatch();
for (int i = 0; i < 10; i++) {
regularSW.Start();
//function();
regularSW.Stop();
Console.WriteLine("Measured time: " + regularSW.Elapsed);
}
Run Code Online (Sandbox Code Playgroud)
我也试图与DateTime
和Process.GetCurrentProcess().TotalProcessorTime
但每次我得到不同的值.
我怎么能得到相同的价值?