C#中测量消耗的内存和时间的方法
1、内存
var start = GC.GetTotalMemory(true);
// todo:待测量的操作
GC.Collect();
GC.WaitForFullGCComplete();
var end = GC.GetTotalMemory(true);
var useMemory = end - start;
2、时间
var watch = new Stopwatch();
watch.Start();
// todo:待测量的操作
watch.Stop();
var useTime = watch.ElapsedMilliseconds;
浙公网安备 33010602011771号