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

Iteration cleanup runs before the benchmark #481

Closed
kayanme opened this issue Jun 23, 2017 · 6 comments
Closed

Iteration cleanup runs before the benchmark #481

kayanme opened this issue Jun 23, 2017 · 6 comments
Assignees
Milestone

Comments

@kayanme
Copy link

kayanme commented Jun 23, 2017

Example:

  class Program
    {

        static void Main(string[] args)
        {      
            BenchmarkDotNet.Running.BenchmarkRunner.Run<BadBench>();
            Console.ReadLine();
        }
    }

   

    
    public class BadBench
    {
        [Benchmark]
        public void Test()
        {
            Console.WriteLine("Test");
            Thread.Sleep(1000);
        }


        [IterationSetup]
        public void Init()
        {
            Console.WriteLine("Init");
        }

        [IterationCleanup]
        public void Clean()
        {
            Console.WriteLine("Clean");
        }
    }

I'm expecting to have "Test" before "Clean", am I? Or do I misunderstand something? Right now it goes right after "Init"
Version 0.10.8

@ig-sinicyn
Copy link
Contributor

It's #464 :)

@kayanme
Copy link
Author

kayanme commented Jun 23, 2017

I saw that bug, but didn't see the same problem. Evenmore, @adamsitnik told about his use case, which, surpisingly, seems working with the correct order. I wonder why.

@AndreyAkinshin AndreyAkinshin self-assigned this Jul 5, 2017
@smitpatel
Copy link
Member

https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet.Core/Templates/BenchmarkProgram.txt#L120
Here is the issue. IterationCleanup is being called before Jitting() Perhaps it does not occur for Monitoring due to Jitting() not being called. I believe the IterationCleanup should be called after Jitting()

For me the use case is like this,
I am creating an object during IterationSetup & disposing it during IterationCleanup. Creating new instance is costly operation so I don't want that in my benchmark method. But due to nature of the benchmark, I need new instance everytime.

@smitpatel
Copy link
Member

@adamsitnik - Thanks for quick response. Is there an estimate when 0.10.9 will make it to NuGet?

@AndreyAkinshin
Copy link
Member

@smitpatel, I want to release next version on this week.

@adamsitnik
Copy link
Member

@smitpatel you get can it today from our CI feed:

<packageSources>
  <add key="bdn-nightly" value="https://ci.appveyor.com/nuget/benchmarkdotnet" />
</packageSources>

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

No branches or pull requests

5 participants