public static void TimeFunction(Point[] arr, CloneFunction func, string label) { Point[] arrCopy = null; long start; long delta; double min = 5000.0d; // big number; // do the whole copy retryCount times, find fastest time for (int retry = 0; retry < retryCount; retry++) { start = Counter.Value; for (int iterate = 0; iterate < iterations; iterate++) { arrCopy = func(arr); } delta = Counter.Value - start; double result = (double)delta / Counter.Frequency; if (result < min) { min = result; } } Console.WriteLine("{0}: {1:F3} seconds", label, min); }
public static void TimeFunction(Point[] sourceArray, CloneFunction cloneFunction, string label) { Point[] result = null; TimeSpan minimumElapsedTime = TimeSpan.MaxValue; Stopwatch stopwatch = new Stopwatch(); // do the whole copy TimeCount times, find fastest time for (int retry = 0; retry < TimeCount; retry++) { stopwatch.Start(); for (int iteration = 0; iteration < Iterations; iteration++) { result = cloneFunction(sourceArray); } stopwatch.Stop(); if (stopwatch.Elapsed < minimumElapsedTime) { minimumElapsedTime = stopwatch.Elapsed; } } Console.WriteLine("{0}: {1} seconds", label, minimumElapsedTime); }