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, dotnet#730
  • Loading branch information
adamsitnik authored and alinasmirnova committed Sep 22, 2018
1 parent 64d1939 commit 2c09474
Show file tree
Hide file tree
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
Expand Up @@ -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))
{
Expand Down
15 changes: 15 additions & 0 deletions tests/BenchmarkDotNet.Tests/Running/BenchmarkConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2c09474

Please sign in to comment.