This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2413|Reply: 0

[Communication] .NET/C# collection List, HashSet to determine whether an element has a benchmark

[Copy link]
Posted on 2/24/2024 5:44:58 PM | | | |
Requirements: To maintain an old project, you need to process data in a loop, and you need to use the primary key to determine whether the elements exist in the collection, and then execute the corresponding logic. How big is the performance gap between using List and HashSet to determine whether there is a performance gap in an element?

Review:

.NET/C# uses BenchmarkDotNet to test code performance
https://www.itsvse.com/thread-9576-1-1.html

.NET/C# collection type query benchmark
https://www.itsvse.com/thread-10268-1-1.html
Test code:

The result is shown below:



N represents the amount of data in the collection, and the larger the number of collections, the worse the List lookup performance, but the HashSet has little impact.





Previous:Introduction and difference between JIT and AOT compilation in .NET
Next:【Practical Combat】OpenWrt installation of luci-app plugin tutorial
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com