Skip to content

Commit

Permalink
if iteration cleanup is provided, the benchmark should be executed on…
Browse files Browse the repository at this point in the history
…ce per iteration, #730
adamsitnik committed Jul 4, 2018
1 parent 844e959 commit 7e2d54e
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Jobs/JobExtensions.cs
Original file line number Diff line number Diff line change
@@ -228,7 +228,7 @@ public static class JobExtensions
internal static Job MakeSettingsUserFriendly(this Job job, Descriptor descriptor)
{
// users expect that if IterationSetup is configured, it should be run before every benchmark invocation https://github.com/dotnet/BenchmarkDotNet/issues/730
if (descriptor.IterationSetupMethod != null
if ((descriptor.IterationSetupMethod != null || descriptor.IterationCleanupMethod != null)
&& !job.HasValue(RunMode.InvocationCountCharacteristic)
&& !job.HasValue(RunMode.UnrollFactorCharacteristic))
{
15 changes: 15 additions & 0 deletions tests/BenchmarkDotNet.Tests/Running/BenchmarkConverterTests.cs
Original file line number Diff line number Diff line change
@@ -83,6 +83,21 @@ public void IfIterationSetupIsProvidedTheBenchmarkShouldRunOncePerIteration()
Assert.Equal(1, benchmark.Job.Run.InvocationCount);
Assert.Equal(1, benchmark.Job.Run.UnrollFactor);
}

[Fact]
public void IfIterationCleanupIsProvidedTheBenchmarkShouldRunOncePerIteration()
{
var benchmark = BenchmarkConverter.TypeToBenchmarks(typeof(WithIterationCleanupOnly)).BenchmarksCases.Single();

Assert.Equal(1, benchmark.Job.Run.InvocationCount);
Assert.Equal(1, benchmark.Job.Run.UnrollFactor);
}

public class WithIterationCleanupOnly
{
[IterationCleanup] public void Cleanup() { }
[Benchmark] public void Benchmark() { }
}

[Fact]
public void InvocationCountIsRespectedForBenchmarksWithIterationSetup()

0 comments on commit 7e2d54e

Please sign in to comment.