所以基本上我想要做的是計算所有停止監視時間的平均值,我的for循環產生並將其放到控制檯。我知道如何取平均值,但我不知道如何將其應用於秒錶時間。請幫忙?如何計算多個秒錶時間的平均值?
for (int index = 0; index < iterations; index++)
{
// loop to generate an array of random numbers
for (int count = 0; count < arrayOfInts.Length; count++)
{
arrayOfInts[count] = r.Next(numitems);
}
// a random array has been created start the clock and sort it
Stopwatch elpased = new Stopwatch();
elpased.Start();
selectionSort(arrayOfInts);
elpased.Stop();
if (iterations == iterations)
{
var average = elpased.Elapsed;
Console.WriteLine ("Time for ___ sort to complete: " + elpased.Elapsed.ToString());
}
}
Console.ReadLine();
}
這是我到目前爲止。
什麼時候'iterations == iterations'永遠是假的? – zzzzBov
可能重複的[查找平均時間集合](http://stackoverflow.com/questions/8847679/find-average-of-collection-of-timespans) –
你說你知道如何取平均值,實際上並沒有取平均水平。 – Brandon