private void PrintData(AlgStats stats) { var actualDoubleFormatted = stats.ActualDoublingRatio < 0 ? "na".PadLeft(20) : stats.ActualDoublingRatio.ToString("F2").PadLeft(20); var expectDoubleFormatted = stats.ExpectedDoublingRatio < 0 ? "na".PadLeft(16) : stats.ExpectedDoublingRatio.ToString("F2").PadLeft(16); Console.Write( $"{stats.TimeMicro,20:F2} {actualDoubleFormatted} {expectDoubleFormatted}" + $"{stats.AlgResult,19:N0} {stats.CorrectnessRatio,23:P1}"); }
private void AlgorithmTestRuntime(Algorithm algorithm, DoublingCalculator doublingCalc) { PrintHeader(algorithm); var currentStats = new AlgStats(); for (var n = NMin; n <= NMax; n *= 2) { currentStats.n = n; if (currentStats.TimeMicro > MaxMicroSecondsPerAlg) { PrintAlgorithmTerminationMessage(algorithm); break; } PrintIndexColumn(currentStats.n); int testCount = 1; int maxTest = 1000000; long tickCounter = 0; while (testCount <= maxTest && TicksToMicroseconds(tickCounter) < MaxMicroSecondsPerIteration) { Graph graph = new EuclideanCircularGraph(n, 100); _stopwatch.Restart(); currentStats.AlgResult = algorithm(graph); _stopwatch.Stop(); // HACK (this should be handled better) currentStats.CorrectnessRatio = ((EuclideanCircularGraph)graph).ShortestRouteCost / (double)currentStats.AlgResult; tickCounter += _stopwatch.ElapsedTicks; testCount++; } double averageTimeMicro = TicksToMicroseconds(tickCounter) / testCount; currentStats.PrevTimeMicro = currentStats.TimeMicro; currentStats.TimeMicro = averageTimeMicro; // Need to keep a dictionary of previous times for doubling calculation on this alg. currentStats.PrevTimesTable.TryAdd(currentStats.n, averageTimeMicro); doublingCalc(currentStats); PrintData(currentStats); // New Row Console.WriteLine(); } }