Skip to content
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

Op/invocation fail to increase due to [IterationCleanup] #1351

Closed
ycrumeyrolle opened this issue Jan 14, 2020 · 4 comments
Closed

Op/invocation fail to increase due to [IterationCleanup] #1351

ycrumeyrolle opened this issue Jan 14, 2020 · 4 comments

Comments

@ycrumeyrolle
Copy link

Similar to #994

This sample benchmark does not increase the op/invocation on warmup when a method is marked with the [IterationCleanup] attribute:

public class TestBenchmark
    {
        [Benchmark]
        [ArgumentsSource(nameof(GetValues))]
        public int Case1(string value)
        {
            return value.Length;
        }

        [Benchmark]
        [ArgumentsSource(nameof(GetValues))]
        public int Case2(string value)
        {
            return value.Length;
        }

        [IterationCleanup]
        public void Clear()
        {
        }

        public IEnumerable<string> GetValues()
        {
            yield return "Value 1";
            yield return "Value 2";
        }
    }

The workload stall at 1.

When removing the [IterationCleanup] attribute, the workload increase as usual.

@abelbraaksma
Copy link

Seems related to #1338. In our, I noticed that the cause seems to be dependent on the situation, but esp the JIT time, causing the algorithm to incorrectly assume it's a long running test.

@abelbraaksma
Copy link

@adamsitnik, this too may be caused by #760. Any thoughts?

@adamsitnik
Copy link
Member

Hi @ycrumeyrolle

This is by design, as described in our docs

A method which is marked by the [IterationCleanup] attribute will be executed exactly once after each invocation. This attribute has the same set of constraint with [IterationSetup]: it's not recommended to use [IterationCleanup] in microbenchmarks.

You can read more about why we made such decision in #730

@ycrumeyrolle
Copy link
Author

@adamsitnik thanks for your reply, I had seen the recommendation to avoid such attribute, but missed the "exactly once".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants