Search code examples
.netbenchmarkdotnet

Should I create separate Benchmark project?


I want to measure performance of some methods in my console application using BenchmarkDotNet library.

The question is: should I create a separate project in my solution where I will copy the methods I am interested in measuring and do the measuring there or should I add all the attributes necessary for measuring into the existing project?

What is the convention here?


Solution

  • You can think about it as of adding unit tests for your console app. You don't add the tests to the app itself, but typically create a new project that references (not copies) the logic that you want to test.

    In my opinion the best approach would be to:

    1. Add a new console app for benchmarks to your solution.
    2. In the benchmarks app, add a project reference to the existing console app.
    3. Add new benchmarks that have all the BDN annotations to the benchmark project, but implement the benchmarks by referencing public types and methods exposed by your console app. Don't copy the code (over time you might introduce changes to one copy and end up testing outdated version).