Is a LINQ statement faster than a 'foreach' loop?

Neil Knight picture Neil Knight · Jul 1, 2010 · Viewed 123.2k times · Source

I am writing a Mesh Rendering manager and thought it would be a good idea to group all of the meshes which use the same shader and then render these while I'm in that shader pass.

I am currently using a foreach loop, but wondered if utilising LINQ might give me a performance increase?

Answer

codymanix picture codymanix · Jul 1, 2010

Why should LINQ be faster? It also uses loops internally.

Most of the times, LINQ will be a bit slower because it introduces overhead. Do not use LINQ if you care much about performance. Use LINQ because you want shorter better readable and maintainable code.