{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/325","repository_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet","labels_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/325/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/325/comments","events_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/325/events","html_url":"https://github.com/dotnet/BenchmarkDotNet/issues/325","id":194874865,"number":325,"title":"Setup & Cleanup versions of attribute which would run before/after each benchmark iteration","user":{"login":"another-guy","id":5762340,"avatar_url":"https://avatars.githubusercontent.com/u/5762340?v=3","gravatar_id":"","url":"https://api.github.com/users/another-guy","html_url":"https://github.com/another-guy","followers_url":"https://api.github.com/users/another-guy/followers","following_url":"https://api.github.com/users/another-guy/following{/other_user}","gists_url":"https://api.github.com/users/another-guy/gists{/gist_id}","starred_url":"https://api.github.com/users/another-guy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/another-guy/subscriptions","organizations_url":"https://api.github.com/users/another-guy/orgs","repos_url":"https://api.github.com/users/another-guy/repos","events_url":"https://api.github.com/users/another-guy/events{/privacy}","received_events_url":"https://api.github.com/users/another-guy/received_events","type":"User","site_admin":false},"labels":[{"id":448462758,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels/Area:Engine","name":"Area:Engine","color":"5319e7","default":false},{"id":52535228,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":{"login":"AndreyAkinshin","id":2259237,"avatar_url":"https://avatars.githubusercontent.com/u/2259237?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreyAkinshin","html_url":"https://github.com/AndreyAkinshin","followers_url":"https://api.github.com/users/AndreyAkinshin/followers","following_url":"https://api.github.com/users/AndreyAkinshin/following{/other_user}","gists_url":"https://api.github.com/users/AndreyAkinshin/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreyAkinshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreyAkinshin/subscriptions","organizations_url":"https://api.github.com/users/AndreyAkinshin/orgs","repos_url":"https://api.github.com/users/AndreyAkinshin/repos","events_url":"https://api.github.com/users/AndreyAkinshin/events{/privacy}","received_events_url":"https://api.github.com/users/AndreyAkinshin/received_events","type":"User","site_admin":false},"assignees":[{"login":"AndreyAkinshin","id":2259237,"avatar_url":"https://avatars.githubusercontent.com/u/2259237?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreyAkinshin","html_url":"https://github.com/AndreyAkinshin","followers_url":"https://api.github.com/users/AndreyAkinshin/followers","following_url":"https://api.github.com/users/AndreyAkinshin/following{/other_user}","gists_url":"https://api.github.com/users/AndreyAkinshin/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreyAkinshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreyAkinshin/subscriptions","organizations_url":"https://api.github.com/users/AndreyAkinshin/orgs","repos_url":"https://api.github.com/users/AndreyAkinshin/repos","events_url":"https://api.github.com/users/AndreyAkinshin/events{/privacy}","received_events_url":"https://api.github.com/users/AndreyAkinshin/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/milestones/6","html_url":"https://github.com/dotnet/BenchmarkDotNet/milestone/6","labels_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/milestones/6/labels","id":1752553,"number":6,"title":"v0.10.x","description":"A temporary milestone that keep all the issues which should be implemented in `v0.10.x`.","creator":{"login":"AndreyAkinshin","id":2259237,"avatar_url":"https://avatars.githubusercontent.com/u/2259237?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreyAkinshin","html_url":"https://github.com/AndreyAkinshin","followers_url":"https://api.github.com/users/AndreyAkinshin/followers","following_url":"https://api.github.com/users/AndreyAkinshin/following{/other_user}","gists_url":"https://api.github.com/users/AndreyAkinshin/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreyAkinshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreyAkinshin/subscriptions","organizations_url":"https://api.github.com/users/AndreyAkinshin/orgs","repos_url":"https://api.github.com/users/AndreyAkinshin/repos","events_url":"https://api.github.com/users/AndreyAkinshin/events{/privacy}","received_events_url":"https://api.github.com/users/AndreyAkinshin/received_events","type":"User","site_admin":false},"open_issues":28,"closed_issues":0,"state":"open","created_at":"2016-05-06T23:03:58Z","updated_at":"2016-12-12T12:53:41Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-12-12T01:51:09Z","updated_at":"2016-12-12T13:14:11Z","closed_at":null,"body":"As I understand, the Setup and Cleanup attributes are invoked once per entire benchmarking session, no matter how many iterations are going to be executed.\r\n\r\nIn my use case I need some similar attribute that will instruct BenchmarkDotNet to run some code before and after each iteration. This is because I am trying to measure the creation time (\"cost\") of the resource-holding object which need to be disposed. Namely, I am trying to measure and compare, whether it's way more costly to create a FileStream on every file operation (Read/Write) or to keep a file stream open for a long time...\r\n\r\n```\r\n    public class FileStreamBenchmark\r\n    {\r\n        private FileStream _fileStream;\r\n\r\n        [Setup] // Setup needs to run before each benchmark iteration\r\n        public void Setup()\r\n        {\r\n            _fileStream = null;\r\n        }\r\n\r\n        [Cleanup] // Cleanup needs to run before each benchmark iteration\r\n        public void Cleanup()\r\n        {\r\n            _fileStream?.Dispose();\r\n        }\r\n\r\n        [Benchmark]\r\n        public void CreateFileStream()\r\n        {\r\n            _fileStream = File.Open(\"somefile.txt\", FileMode.OpenOrCreate, FileAccess.ReadWrite);\r\n            // ... some read/write code\r\n        }\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/comments/266427960","html_url":"https://github.com/dotnet/BenchmarkDotNet/issues/325#issuecomment-266427960","issue_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/325","id":266427960,"user":{"login":"AndreyAkinshin","id":2259237,"avatar_url":"https://avatars.githubusercontent.com/u/2259237?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreyAkinshin","html_url":"https://github.com/AndreyAkinshin","followers_url":"https://api.github.com/users/AndreyAkinshin/followers","following_url":"https://api.github.com/users/AndreyAkinshin/following{/other_user}","gists_url":"https://api.github.com/users/AndreyAkinshin/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreyAkinshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreyAkinshin/subscriptions","organizations_url":"https://api.github.com/users/AndreyAkinshin/orgs","repos_url":"https://api.github.com/users/AndreyAkinshin/repos","events_url":"https://api.github.com/users/AndreyAkinshin/events{/privacy}","received_events_url":"https://api.github.com/users/AndreyAkinshin/received_events","type":"User","site_admin":false},"created_at":"2016-12-12T13:14:11Z","updated_at":"2016-12-12T13:14:11Z","body":"Similar issues: https://github.com/dotnet/BenchmarkDotNet/issues/270, https://github.com/dotnet/BenchmarkDotNet/issues/274\r\n\r\nIs seems that it is a popular request. Originally, BenchmarkDotNet was designed for microbenchmarks (in this case, the Setup/Cleanup methods can easily spoil results). However, if a benchmark takes some time (e.g. more than `1ms`), such feature looks valid. I'm going to implement another `RunStrategy` which will support such cases (+ additional analyzers which check that we could use this strategy for a given benchmark).\r\n\r\n@another-guy, why you couldn't include the bodies of `Setup` and `Cleanup` in the `CreateFileStream` method? "}}
{"actor":{"display_login":"AndreyAkinshin"}}