Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between the performance of list.FindAll and for loops in C #

Shulou Source: shulou.com Published: 2022-06-03 19:12:07 11月12日 Update

This article is about the difference between the performance of list.FindAll and for loops in c #. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Preface

Recently, I saw an article on the Internet, which said: the efficiency of List.FindAll is even worse than that of for loop. Here is a screenshot of the article:

The above is an article from baidu, which surprised me, because I have used a lot of FindAll in the AI module. But is the above conclusion true?

I have added multiple tests to the above code:

The following results are obtained:

.Net2.0, visual studio executes 1, 1, 1, 100, 1, 000 times:

.Net4.1, visual studio executes 1, 1, 1, 1, 100, 1, 000 times:

Unity preprocesses and then executes 1000 times:

Unity is preprocessed and then executed 10 times.

Unity is preprocessed and then executed once.

My test program shows that the efficiency of List.FindAll is not "50 or 60 times worse than the for cycle", whether on windows or unity platform. The fact is that because the algorithm site is initialized, the process's first call to List.FindAll takes 50 or 60 times longer than the for loop. However, the performance difference between the List.FindAll and for loops after the first call is very small and can be ignored.

Thank you for reading! This is the end of the article on "what is the difference between the performance of list.FindAll and for loop in c #". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Loops articles performance preprocessing caching above code content platform efficiency articles more first time testing good practical surprised amazed facts preface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux vpn MySQL Shulou Tech Info