6

Collection Performance: Looping Over Collection – Array vs. List – dotNetTips.co...

 2 years ago
source link: https://dotnettips.wordpress.com/2021/10/27/collection-performance-looping-over-collection-array-vs-list/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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. ArrayAs you can see, Array is faster than List<> in both cases.

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

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

Tagged Code Performance

I live in San Diego, Ca USA View all posts by dotNetDave


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK