To determine the presence of items in a ConcurrentBag<>
, you can employ either the Count
property or the IsEmpty()
method. Let’s compare the performance of these two approaches.
Benchmark Results
The benchmark results reveal that, overall, utilizing IsEmpty() is 3.03 times more efficient than relying on Count.
This is how I have it setup in my EditorConfig to check for this issue: dotnet_diagnostic.CA1836.severity = error
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave
© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.