Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report