v0.6.1 ||

C# Performance Recorder

C# performance recorder library using aspect oriented programming

Gitlab
Docs
MIT

2019.10.16 2022.03.31

Project archived on 18 November 2022


The goal of this project was to create a way to track performance of C# methods.

It started out as a simple function that took another function and logged how long it took to run - one of the simplest ways to track method execution time. This was a great start, but it creates a lot of boilerplate code that doesn't add any business value.

So I evolved the concept to use AOP (Aspect Oriented Programming) by leveraging the AspectInjector library. The goal was to allow any method to be tracked by simply adding an annotation to it - no other code changes required.

I have applied this library to other projects to better understand what functions take the most time to run and track down any performance bottlenecks. It has taught me that sometimes the thing I assume to take the longest time to run is actually pretty quick - and vice-versa.


Using the project is pretty straight-forward. Add the [PerformanceLogging] annotation to any method you want to record, then print out the results after you run your code.

The output looks something like this:

+-
   +- ApplicationImpl.RunApplication              count:  1  sum: 1.85  avg: 1.85  max: 1.85  min: 1.85
      +- WorkerImpl.RunOperationB                 count:  1  sum: 1.13  avg: 1.13  max: 1.13  min: 1.13
      |  +- WorkerImpl.RunPrivateOperationB2      count:  1  sum: 0.41  avg: 0.41  max: 0.41  min: 0.41
      |  |  +- WorkerImpl.RunPrivateOperationB21  count:  1  sum: 0.00  avg: 0.00  max: 0.00  min: 0.00
      +- ApplicationImpl.Worker                   count: 11  sum: 0.16  avg: 0.01  max: 0.14  min: 0.00
         +- WorkerImpl..ctor                      count: 11  sum: 0.00  avg: 0.00  max: 0.00  min: 0.00

Take a look at the project documentation or example project for more details.