Closed mattwarren closed 8 years ago
Good idea! I would also Dispose the object if it is IDisposable (at the end)
@adamsitnik I'm not following, which object do you mean?
@mattwarren the one that is implementing Benchmark method(s)
@mattwarren, can you write an example of benchmark where we need a cleanup method?
This idea came from this tweet, but I'm not really sure of the exact scenario, I'll try and find out.
I think that Aaronontheweb (as a contributor to NBench) at his tweet said about "Cleanup" logic after each iteration. But BenchmarkDotNet uses "Setup" attribute for set of iterations called "Launch" (I hope so). That's why I think that "Cleanup" attribute could be used at benchmarks that do some work with "out of the process" resources - filesystem, for example.
It makes sense, but I still want to have a real use-case for cleanup.
Hi all - thanks for the great project!
We're using BenchmarkDotNet to profile a new Serilog "async" sink, and we need to:
...after running a benchmark. Without [Cleanup]
it's hard to do this properly.
Does this cover the scenario information you need to consider including this feature?
Thanks!
Ah, now I see the commit above - great! Sorry about the noise :-)
@nblumhardt If you don't want to wait for 0.9.9 release you can download the pre-release package from our development feed <add key="appveyor-bdn" value="https://ci.appveyor.com/nuget/benchmarkdotnet" />
If that's not an option you can add a finalizer to your benchmark class. But personally I don't like this workaround.
To mirror the invocations of the
[Setup]
method, i.e.[Setup]
[Cleanup]
This is useful when there is a resource that needs cleaning up after each set of iterations