7

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?

1 Answer 1

6

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).
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the tips! Especially the last one since I was in the process of copying everything to new project :D Makes more sense to reference it.
Any suggestions on naming conventions? For tests, folder tests in the root of the repo is quite common and the .Tests suffix in the project name is a standard, too. I have seen many variations when the unit, integration, and E2E tests are differentiated, but separate folders under the tests folder make sense to me and keeping the same suffix for all seems OK as only the unit tests will have 1:1 correspondence with the implementation projects. But where to put the benchmarks? For now, I opted for benches in the repo root and .Benchmarks suffix.
@Palec .Benchmarks suffix sounds very good to me. When it comes to the subfolder name I am not 100% sure myself. My current approach would be to keep it under tests if that is the only benchmark project for given repo solution. If you have more benchmark projects I would move them to dedicated, benchmarks subfolder (on the same level as src and tests)
I went for benches to keep the folder name short. Though even about bench. The reason for a separate folder from tests is separate treatment by the pipelines -- benchmarks may need to run separately from tests, possibly not during all builds, and they have different outputs.
@Dario We don't provide that and I doubt we ever will.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.