I made a few classes for processing and validating data in xlsx and csv.
However, I am curious in testing how fast the methods I wrote in C# for the heavy lifting are.
Here’s what I currently am thinking of (written in C#):
// use this to test the performance of the method on files with various sizes
class FileProcessorPerformance
{
private static Stopwatch sw;
public static Stopwatch PerformanceSpeedStart()
{
sw = new Stopwatch();
sw.Start();
return sw;
}
public static void PerformanceSpeedEnd(Stopwatch stopwatch)
{
stopwatch.Stop();
TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("Run Time: " + elapsedTime);
}
}
An usage example would be like:
Stopwatch sw = PerformanceSpeedStart()
ProcessData();
PerformanceSPeedEnd(sw);
Besides using logic such as time complexity (big-O), how do people benchmark their solutions, if they do at all?
Thanks!
2
For a single simple method, using a stopwatch can work well. For larger, more intricate code, though, what you want is a profiler, an external tool that attaches to your program as a debugger, lets you run it, and monitors how long the code that you’re executing takes and where the time is being spent.
When you’re finished, it gives you a statistical report explaining where you’re spending most of your time, which you can generally drill-down into to get a more detailed look at it. Profilers can take a bit of work to understand how to use them, but they’re extremely powerful for performance tuning once you’ve learned.
4