From fc8d9260d520a9b78bb517019730702989ee462e Mon Sep 17 00:00:00 2001 From: Paul Nitzke <14367-paulenit@users.noreply.git.rwth-aachen.de> Date: Sat, 9 Jul 2022 22:05:20 +0200 Subject: [PATCH] Add small profiling example * We can use the Stopwatch class to time the execution of our program. * This commit implements this experimentally for the partition to colored dot execution path. * This is considered a work in progress and should NOT be merged into master. * A proper implementation would likely involve some overseeing structure in ConversionManager for the execution methods to hook into and provide their timing * The goal is to design this independent from the frontend so an interface to the frontend must also be provided. --- src/SparseTransform/ConversionManager.cs | 45 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/SparseTransform/ConversionManager.cs b/src/SparseTransform/ConversionManager.cs index 5fc419b..ca79cd2 100644 --- a/src/SparseTransform/ConversionManager.cs +++ b/src/SparseTransform/ConversionManager.cs @@ -1,5 +1,6 @@ using SparseTransform.DataStructures; using SparseTransform.Convert; +using System.Diagnostics; namespace SparseTransform { @@ -29,19 +30,53 @@ namespace SparseTransform public static String Partition2ColoredDot(String MMMatrix, bool textColor = false) { MatrixMarketReader reader = new MatrixMarketReader(); + + Stopwatch inWatch = Stopwatch.StartNew(); + IGraph graph = reader.ReadGraph(MMMatrix); + + inWatch.Stop(); + TimeSpan inTime = inWatch.Elapsed; + Colorer color = new Colorer(); - if (graph is AdjacencyGraph) - { - - color.StarColor1((AdjacencyGraph) graph); + Stopwatch colWatch = Stopwatch.StartNew(); + if (graph is AdjacencyGraph) + { + color.StarColor1((AdjacencyGraph)graph); } else + { color.PartialD2Color((BipartiteGraph)graph); + } + + colWatch.Stop(); + TimeSpan colTime = colWatch.Elapsed; + ColoredDotWriter writer = new ColoredDotWriter(graph, textColor); - return writer.Write(graph); + + Stopwatch outWatch = Stopwatch.StartNew(); + + String dotOutput = writer.Write(graph); + + outWatch.Stop(); + TimeSpan outTime = outWatch.Elapsed; + + string inTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + inTime.Hours, inTime.Minutes, inTime.Seconds, + inTime.Milliseconds / 10); + + string colTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + colTime.Hours, colTime.Minutes, colTime.Seconds, + colTime.Milliseconds / 10); + + string outTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + outTime.Hours, outTime.Minutes, outTime.Seconds, + outTime.Milliseconds / 10); + + Console.WriteLine($"Time elapsed in ConversionManager:\nIn-Transformation:\t{inTimeOutput}\nColoring:\t\t{colTimeOutput}\nOut-Transformation:\t{outTimeOutput}\n"); + return dotOutput; } /// <summary> -- GitLab