New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation warning for sealed
classes containing benchmarks
#2516
Comments
Your benchmark class cannot be sealed because BDN generates a class that inherits it in order to actually run the benchmarks.
|
Perhaps it would be better to display a warning rather than ignore it silently. |
sealed
sealed
classes containing benchmarks
@timcassell, All right, my question was based on general ignorance, and this is clearly much more complex than I had imagined. There are likely a variety of different ways BenchmarkDotNet could be used. In our use, it seems the template was not used. But then I did not actually have the attribute After having seen the template public int BenchmarkDotNet { get; set; } to make sure the code in the template will not compile, I do see output indicating the compile-time error, so I can see that a template is used then. However (removing the evil public Md5VsSha256()
{
if (GetType() != typeof(Md5VsSha256))
{
throw new InvalidOperationException("See, template type is instantiated.");
}
} then I do not see any indication that the line 6 from the template, Anyway, this is probably not worth pursuing further. Thank you for your answer. |
We should reconsider writing the code analyzers for BDN, similar to what xUnit provides. |
It is easy to create benchmarks, for example as shown in README.md:
However, if I choose to seal my class, as in:
then if I use
BenchmarkSwitcher.FromAssemblies(...).Run(...)
to run my benchmarks, then the class is no longer discovered.Is there any technical reason for this behavior?
It seems that if you go to src/BenchmarkDotNet/Extensions/ReflectionExtensions.cs line 159 and remove the
.IsSealed
criterion, then this should work?In the project I am working in, we prefer to make all types
sealed
unless they are specifically designed to be base classes, and this practice improves performance in general, so it is a shame if classes containing benchmarks cannot also besealed
.The text was updated successfully, but these errors were encountered: