我想在 C# 或 C++ 或 C 中改进一些方法。
为了测量时间,我可以使用 Stopwatch 类,但另外我想测量由已删除代码保留的内存。您知道任何与下面代码中使用的 MemoryMeasure 类具有相似属性的类或方法吗?
Stopwatch s1 = Stopwatch.StartNew();
MemoryMeasure m1 = MemoryMeasure.Start();
for (int i = 0; i < m; i++)
{
//some compute
//for example
//var x = new LargeObject(new SmallObject(), 45);
//some compute
//some compute
}
m1.Stop();
s1.Stop();
Console.Writeline("Your code was executed in " + s1.ElapsedMilliseconds + "ms");
Console.Writeline("Your code ate " + m1.UsedMemory + "MB of memory");