There are occasions when writing complex code logic where the performance outcomes of an algorithm or method are uncertain. In such scenarios, it’s valuable to conduct performance testing on your code, commonly referred to as benchmarking.

Understanding Benchmarking

Benchmarking involves systematically evaluating the performance of your code to gain insights into its efficiency, execution time, and resource utilization. It allows developers to make informed decisions about choosing the optimal solution among various alternatives based on quantitative data. Essentially we can run code with the benchmarking tools and get direct feedback on the performance.

When Benchmarking is Beneficial

  • When estimating time and space complexities for various options, and you want to gauge their performance under more realistic scenarios relevant to the use case.
  • When the logic becomes intricate and calculating time complexity becomes challenging.
  • When multiple methods from external libraries can accomplish a task, and you seek to compare their performance since they weren’t authored by you.

Conclusion

This post provides a concise overview of benchmarking and its usefulness. While we won’t delve into the specifics of employing benchmarking in C# here, there are comprehensive articles on this topic available. One example is How to benchmark C# code using BenchmarkDotNet, which provides thorough insights into benchmarking techniques.