dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.36k stars 4.74k forks source link

FrozenDictionary.TryGetValue is consistently slower than ConcurrentDictionary.TryGetValue for integer keys #96274

Open eiriktsarpalis opened 10 months ago

eiriktsarpalis commented 10 months ago

JFYI

Added FrozenDictionary to the mix in alternate version of becnhmark

Method ItemCount Mean Error StdDev
DictionarySearch 1 6.946 ns 0.0713 ns 0.0632 ns
FrozenDictionarySearch 1 5.325 ns 0.0839 ns 0.0785 ns
ConcurrentDictionarySearch 1 4.516 ns 0.0548 ns 0.0486 ns
DictionarySearch 20 146.208 ns 1.4250 ns 1.3329 ns
FrozenDictionarySearch 20 111.611 ns 1.1177 ns 1.0455 ns
ConcurrentDictionarySearch 20 86.620 ns 0.8611 ns 0.8055 ns
DictionarySearch 50 355.210 ns 1.3703 ns 1.1443 ns
FrozenDictionarySearch 50 274.595 ns 3.9317 ns 3.4853 ns
ConcurrentDictionarySearch 50 206.804 ns 2.0069 ns 1.8773 ns
DictionarySearch 777 5,459.453 ns 49.4440 ns 46.2499 ns
FrozenDictionarySearch 777 3,838.004 ns 76.0184 ns 90.4945 ns
ConcurrentDictionarySearch 777 3,168.900 ns 54.7730 ns 51.2347 ns

Originally posted by @gurustron in https://github.com/dotnet/runtime/discussions/96272#discussioncomment-7927338

ghost commented 10 months ago

Tagging subscribers to this area: @dotnet/area-system-collections See info in area-owners.md if you want to be subscribed.

Issue Details
JFYI Added `FrozenDictionary` to the mix in [alternate version of becnhmark](https://gist.github.com/gurustron/ea818ccf32a9c4decc27bde1859835f8#file-dictsearchwithconsumebenchmarks_multiplecounts-cs) | Method | ItemCount | Mean | Error | StdDev | |--------------------------- |---------- |-------------:|-----------:|-----------:| | DictionarySearch | 1 | 6.946 ns | 0.0713 ns | 0.0632 ns | | FrozenDictionarySearch | 1 | 5.325 ns | 0.0839 ns | 0.0785 ns | | ConcurrentDictionarySearch | 1 | 4.516 ns | 0.0548 ns | 0.0486 ns | | DictionarySearch | 20 | 146.208 ns | 1.4250 ns | 1.3329 ns | | FrozenDictionarySearch | 20 | 111.611 ns | 1.1177 ns | 1.0455 ns | | ConcurrentDictionarySearch | 20 | 86.620 ns | 0.8611 ns | 0.8055 ns | | DictionarySearch | 50 | 355.210 ns | 1.3703 ns | 1.1443 ns | | FrozenDictionarySearch | 50 | 274.595 ns | 3.9317 ns | 3.4853 ns | | ConcurrentDictionarySearch | 50 | 206.804 ns | 2.0069 ns | 1.8773 ns | | DictionarySearch | 777 | 5,459.453 ns | 49.4440 ns | 46.2499 ns | | FrozenDictionarySearch | 777 | 3,838.004 ns | 76.0184 ns | 90.4945 ns | | ConcurrentDictionarySearch | 777 | 3,168.900 ns | 54.7730 ns | 51.2347 ns | _Originally posted by @gurustron in https://github.com/dotnet/runtime/discussions/96272#discussioncomment-7927338_
Author: eiriktsarpalis
Assignees: -
Labels: `area-System.Collections`
Milestone: -