{"action":"opened","number":760,"pull_request":{"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760","id":189757352,"html_url":"https://github.com/dotnet/BenchmarkDotNet/pull/760","diff_url":"https://github.com/dotnet/BenchmarkDotNet/pull/760.diff","patch_url":"https://github.com/dotnet/BenchmarkDotNet/pull/760.patch","issue_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/760","number":760,"state":"open","locked":false,"title":"don't execute long operations more than once per iteration","user":{"login":"adamsitnik","id":6011991,"avatar_url":"https://avatars2.githubusercontent.com/u/6011991?v=4","gravatar_id":"","url":"https://api.github.com/users/adamsitnik","html_url":"https://github.com/adamsitnik","followers_url":"https://api.github.com/users/adamsitnik/followers","following_url":"https://api.github.com/users/adamsitnik/following{/other_user}","gists_url":"https://api.github.com/users/adamsitnik/gists{/gist_id}","starred_url":"https://api.github.com/users/adamsitnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamsitnik/subscriptions","organizations_url":"https://api.github.com/users/adamsitnik/orgs","repos_url":"https://api.github.com/users/adamsitnik/repos","events_url":"https://api.github.com/users/adamsitnik/events{/privacy}","received_events_url":"https://api.github.com/users/adamsitnik/received_events","type":"User","site_admin":false},"body":"Background: because of the default unroll factor = 16, every iteration was invoking benchmark at least 16 times. \r\n\r\nSo if the benchmark took 1s, then:\r\n\r\n1. jitting took 16x1s\r\n2. warmup took 6 (MinIterationCount for EngineWarmupStage)  x 16 x 1s = 96 s\r\n3. every target iteration was taking 16s\r\n\r\n**Note:** In the default mode, this was described in our docs and was possible to change with custom config. We just did not have the time to fix it.\r\n\r\n\r\nThis PR introduces following changes:\r\n\r\n1. EngineFactory is supposed to create an engine which is \"ready to run\", which means it's supposed to call `GlobalSetup`. (hence the method name change `Create` => `CreateReadyToRun`)\r\n2. Engine implements `IDisposable`, which calls `GlobalCleanup`\r\n3. When the strategy requires us to jit the code first (default mode) and to run the pilot (no explicit value for invocationCount), the engine factory does jitting and **also checks how long does it take to run the benchmark once** (unrol factor=invocation count=1).\r\n a. If it took longer than IterationTime (0.5s by default), the engine is created for job with one invocation per iteration\r\n b. otherwise, old rules applies\r\n4. Strategies which don't require jitting don't follow this path (by design)\r\n5. I had to duplicate both the C# and IL we generate to have possibility to choose the mode and keep the Engine immutable. It does not look as bad as  I expected it to look ;)\r\n6. Because the changes applies mostly to `EngineFactory`, I was able to write some nice unit tests (not integration tests)\r\n\r\n```cs\r\npublic class Sleeep\r\n{\r\n    [Benchmark] public void Sleep1s() => Thread.Sleep(TimeSpan.FromSeconds(1));\r\n}\r\n```\r\n\r\nBefore: Total time: 00:06:16 (376.01 sec)\r\nAfter:   Total time: 00:00:27 (27.88 sec)\r\n\r\nThis fixes #736, makes #730 easy and contributes to #550.\r\n\r\n@AndreyAkinshin please take a look ;)\r\n@krzysztofcwalina this fixes the issue you have faced in ML.NET","created_at":"2018-05-22T18:46:02Z","updated_at":"2018-05-22T18:46:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":448462758,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels/Area:Engine","name":"Area:Engine","color":"a1e0ed","default":false},{"id":52535228,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760/commits","review_comments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760/comments","review_comment_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/760/comments","statuses_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/statuses/773c47f4ec944767b88cc0393dfb8b7d8ea5904f","head":{"label":"dotnet:unrollFactor1","ref":"unrollFactor1","sha":"773c47f4ec944767b88cc0393dfb8b7d8ea5904f","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":12191244,"name":"BenchmarkDotNet","full_name":"dotnet/BenchmarkDotNet","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/BenchmarkDotNet","description":"Powerful .NET library for benchmarking","fork":false,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet","forks_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/forks","keys_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/teams","hooks_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/hooks","issue_events_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/events","assignees_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/tags","blobs_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/languages","stargazers_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/stargazers","contributors_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/contributors","subscribers_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/subscribers","subscription_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/subscription","commits_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/merges","archive_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/downloads","issues_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/deployments","created_at":"2013-08-18T06:17:48Z","updated_at":"2018-05-22T08:24:32Z","pushed_at":"2018-05-22T18:20:45Z","git_url":"git://github.com/dotnet/BenchmarkDotNet.git","ssh_url":"git@github.com:dotnet/BenchmarkDotNet.git","clone_url":"https://github.com/dotnet/BenchmarkDotNet.git","svn_url":"https://github.com/dotnet/BenchmarkDotNet","homepage":"http://benchmarkdotnet.org/","size":15554,"stargazers_count":2910,"watchers_count":2910,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":305,"mirror_url":null,"archived":false,"open_issues_count":98,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":305,"open_issues":98,"watchers":2910,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"4665ec5714075f4f25535deaa606f52a76fa4921","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":12191244,"name":"BenchmarkDotNet","full_name":"dotnet/BenchmarkDotNet","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/BenchmarkDotNet","description":"Powerful .NET library for benchmarking","fork":false,"url":"https://api.github.com/repos/dotnet/BenchmarkDotNet","forks_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/forks","keys_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/teams","hooks_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/hooks","issue_events_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/events","assignees_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/tags","blobs_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/languages","stargazers_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/stargazers","contributors_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/contributors","subscribers_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/subscribers","subscription_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/subscription","commits_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/merges","archive_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/downloads","issues_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/BenchmarkDotNet/deployments","created_at":"2013-08-18T06:17:48Z","updated_at":"2018-05-22T08:24:32Z","pushed_at":"2018-05-22T18:20:45Z","git_url":"git://github.com/dotnet/BenchmarkDotNet.git","ssh_url":"git@github.com:dotnet/BenchmarkDotNet.git","clone_url":"https://github.com/dotnet/BenchmarkDotNet.git","svn_url":"https://github.com/dotnet/BenchmarkDotNet","homepage":"http://benchmarkdotnet.org/","size":15554,"stargazers_count":2910,"watchers_count":2910,"language":"C#","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":305,"mirror_url":null,"archived":false,"open_issues_count":98,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":305,"open_issues":98,"watchers":2910,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760"},"html":{"href":"https://github.com/dotnet/BenchmarkDotNet/pull/760"},"issue":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/760"},"comments":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/issues/760/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/pulls/760/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/BenchmarkDotNet/statuses/773c47f4ec944767b88cc0393dfb8b7d8ea5904f"}},"author_association":"MEMBER","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":8,"additions":318,"deletions":118,"changed_files":15}}
{"actor":{"display_login":"adamsitnik"}}