Collection Performance: Looping Over Collection – Array vs. List

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

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If 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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.