Comments on: LINQ versus looping–Performance https://www.anujvarma.com/linq-versus-loopingperformance/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Thu, 22 Jan 2015 10:06:53 +0000 hourly 1 https://wordpress.org/?v=6.9.4 By: anon https://www.anujvarma.com/linq-versus-loopingperformance/#comment-9600 Thu, 22 Jan 2015 10:06:53 +0000 http://www.anujvarma.com/linq-versus-loopingperformance/#comment-9600 Hi there, your still only executing the LINQ query once (the LINQ results finishes with 100 items vs 10100).

Change searchResults in the LINQ query to be an integer array and AddRange the LINQ select to it. Both arrays will now match but the LINQ will be clearly slower.

]]>
By: Anuj Varma https://www.anujvarma.com/linq-versus-loopingperformance/#comment-9578 Wed, 21 Jan 2015 19:33:58 +0000 http://www.anujvarma.com/linq-versus-loopingperformance/#comment-9578 In reply to anon.

Thanks for the feedback. I tried it with the .count on the Linq Results. LINQ still seems to outperform the for loop significantly (see attached source code).

]]>
By: anon https://www.anujvarma.com/linq-versus-loopingperformance/#comment-9411 Tue, 13 Jan 2015 11:59:54 +0000 http://www.anujvarma.com/linq-versus-loopingperformance/#comment-9411 This article is very misleading, you’re not doing anything with the LINQ result so of course the performance is better… it’s not being executed! Do something with the LINQ result (get a count of the matches for example) and you will see the performance is worse than the foreach loop. Your also sticking all the foreach loop results into a single array while not doing the same with LINQ.

]]>
By: Replacing foreach loops with LINQ expressions–A performance gain | Anuj Varma, Technical Architect https://www.anujvarma.com/linq-versus-loopingperformance/#comment-539 Tue, 08 Oct 2013 16:51:11 +0000 http://www.anujvarma.com/linq-versus-loopingperformance/#comment-539 […] general Yes – but not always. For smaller sized collections, a foreach loop may outperform a linq expression. A bit surprising, but true. However, as collection sizes grow, LINQ clearly outperforms foreach […]

]]>