{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/28188","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/28188/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/28188/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/28188/events","html_url":"https://github.com/dotnet/corefx/issues/28188","id":306352019,"number":28188,"title":"ConcurrentDictionary<,>.IsEmpty is barely faster than checking Count","user":{"login":"yaakov-h","id":426009,"avatar_url":"https://avatars1.githubusercontent.com/u/426009?v=4","gravatar_id":"","url":"https://api.github.com/users/yaakov-h","html_url":"https://github.com/yaakov-h","followers_url":"https://api.github.com/users/yaakov-h/followers","following_url":"https://api.github.com/users/yaakov-h/following{/other_user}","gists_url":"https://api.github.com/users/yaakov-h/gists{/gist_id}","starred_url":"https://api.github.com/users/yaakov-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaakov-h/subscriptions","organizations_url":"https://api.github.com/users/yaakov-h/orgs","repos_url":"https://api.github.com/users/yaakov-h/repos","events_url":"https://api.github.com/users/yaakov-h/events{/privacy}","received_events_url":"https://api.github.com/users/yaakov-h/received_events","type":"User","site_admin":false},"labels":[{"id":154923328,"url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Collections","name":"area-System.Collections","color":"d4c5f9","default":false},{"id":309869280,"url":"https://api.github.com/repos/dotnet/corefx/labels/question","name":"question","color":"207de5","default":true},{"id":153500238,"url":"https://api.github.com/repos/dotnet/corefx/labels/tenet-performance","name":"tenet-performance","color":"c2e0c6","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-03-19T07:00:35Z","updated_at":"2018-03-20T03:13:08Z","closed_at":"2018-03-20T03:13:08Z","author_association":"COLLABORATOR","body":"I would assume that a specialist method named `IsEmpty` is significantly faster than simply obtaining the `Count` of a `ConcurrentDictionary<,>`, yet it appears to be just a touch slower.\r\n\r\nx-ref https://github.com/WiseTechGlobal/WTG.Analyzers/pull/23#issuecomment-374116037\r\n\r\nSimilar to the benchmark in the linked above, here's a benchmark comparing an empty dictionary to one containing 1,200 items.\r\n\r\nI would expect `Empty_IsEmpty` to take roughly the same amount of time as `Contents_IsEmpty`, but it appears to scale up similarly to testing against `Count`.\r\n\r\n```\r\n// * Summary *\r\n\r\nBenchmarkDotNet=v0.10.13, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.309)\r\nIntel Core i5-7600K CPU 3.80GHz (Kaby Lake), 1 CPU, 4 logical cores and 4 physical cores\r\nFrequency=3703123 Hz, Resolution=270.0423 ns, Timer=TSC\r\n.NET Core SDK=2.1.100-preview-007326\r\n  [Host]     : .NET Core 2.0.5 (CoreCLR 4.6.26020.03, CoreFX 4.6.26018.01), 64bit RyuJIT\r\n  DefaultJob : .NET Core 2.0.5 (CoreCLR 4.6.26020.03, CoreFX 4.6.26018.01), 64bit RyuJIT\r\n\r\n\r\n           Method |        Mean |     Error |    StdDev |  Gen 0 | Allocated |\r\n----------------- |------------:|----------:|----------:|-------:|----------:|\r\n    Empty_IsEmpty |    67.29 ns | 0.0808 ns | 0.0716 ns |      - |       0 B |\r\n      Empty_Count |    67.49 ns | 0.0255 ns | 0.0199 ns |      - |       0 B |\r\n    Empty_LinqAny |   180.82 ns | 0.1109 ns | 0.0926 ns | 0.0203 |      64 B |\r\n Contents_IsEmpty | 3,907.88 ns | 1.8701 ns | 1.7493 ns |      - |       0 B |\r\n   Contents_Count | 4,129.74 ns | 1.5337 ns | 1.3596 ns |      - |       0 B |\r\n Contents_LinqAny |    42.68 ns | 0.0471 ns | 0.0417 ns | 0.0203 |      64 B |\r\n\r\n```\r\n\r\nIs `IsEmpty` actually doing anything special or could the implementation just about be replaced with:\r\n\r\n```csharp\r\npublic bool IsEmpty => Count == 0;\r\n```\r\n\r\n?\r\n\r\nI don't actually see a huge difference in the two implementations."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/374458831","html_url":"https://github.com/dotnet/corefx/issues/28188#issuecomment-374458831","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/28188","id":374458831,"user":{"login":"yaakov-h","id":426009,"avatar_url":"https://avatars1.githubusercontent.com/u/426009?v=4","gravatar_id":"","url":"https://api.github.com/users/yaakov-h","html_url":"https://github.com/yaakov-h","followers_url":"https://api.github.com/users/yaakov-h/followers","following_url":"https://api.github.com/users/yaakov-h/following{/other_user}","gists_url":"https://api.github.com/users/yaakov-h/gists{/gist_id}","starred_url":"https://api.github.com/users/yaakov-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaakov-h/subscriptions","organizations_url":"https://api.github.com/users/yaakov-h/orgs","repos_url":"https://api.github.com/users/yaakov-h/repos","events_url":"https://api.github.com/users/yaakov-h/events{/privacy}","received_events_url":"https://api.github.com/users/yaakov-h/received_events","type":"User","site_admin":false},"created_at":"2018-03-20T03:13:08Z","updated_at":"2018-03-20T03:13:08Z","author_association":"COLLABORATOR","body":"Hmm, thanks."}}
{"actor":{"display_login":"yaakov-h"}}