Updated January 2024
Most of the benchmarks in this book that test a collection are performed using List<>
with a real-world business object Person
as a reference type. I was curious about how that would compare to using an array of Person
.
Benchmark Results
Here are the benchmark results for iterating over an Array compared to a List<>
collection of reference types using for()
and foreach()
.
As evident from these results, utilizing an array is 7.5 times faster.
As evident from these results, using an array is 7.6 times faster.
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.
One thought on “Collection Performance: Looping Over Collection – Array vs. List”