Collection Performance: Looping Over Collection – Array vs. List

Most of the benchmarks these articles tests a collection is doing so using List<> that uses a real-world business object (Person). I was curious about how that would perform against using an array of Person.

Benchmark Results

Below are the benchmark results for looping over an array compared to a List<> collection using for() and foreach().

for(): List<> vs. Array

foreach(): List<> vs. Array
As you can see, Array is faster than List<> in both cases.

Pick up any books by David McCarter by going to

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.

The benchmark results in this article are only for your reference. Your results will be different, so make sure to benchmark your code using Benchmarkdotnet.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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