Benchmarking C# Code
I occasionally need to benchmark some code. In C#, this can easily be done using the Stopwatch class. After writing the same boilerplate Stopwatch wrapper enough times I decided to throw together a simple Benchmarker class.
This allows any code to be easily called and timed. For example, suppose you have a void Method called Foo
. This can be timed via:
Similarly, if you want to benchmark a method that happens to return something like this
you can use the above Benchmarker class via
I’ve put this on github: https://github.com/mattnedrich/tools/tree/master/csharp/Benchmarker.cs