如何知道 C# 中的方法需要多少时间 例如,我有 label1 和方法
public int MakeSome(int a, int b)
{
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
// some operation
}
}
return returnIntValue;
}
知道,如何知道多少毫秒采取MakeSome方法,并将值写入label1。 谢谢
最佳答案
您可以使用 Stopwatch
类:
Stopwatch st = new Stopwatch();
st.Start();
// call MakeSome method...
st.Stop();
然后您可以检查 st.ElapsedMilliseconds
属性。
关于c# - 方法运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2115560/