I come from Java programming and switching to C# programming I discovered the extreme powerful of LINQ.
In my recent implementation I noticed that I use it (expecially LINQ to Objects) very often in my code to avoid foreach loops, to search elements in lists and for similar tasks.
Now I’m wondering if there is some performance disadvantage in massively use Linq to Objects…
Linq is slower than native C# loops.
C# is slower than C++.
C++ is slower than assembly.
Assembly is slower than designing your own custom microprocessor.
So you should always design your own custom microprocessor instead of using Linq…..
Is there a performance hit? Probably, but you won’t know how much until you actually measure it. It may be small enough that it won’t be significant and you can spend the time you would have spent avoiding Linq tackling the parts of the application that do benefit by optimization.
Bottom line is – build your app using the libraries and frameworks that make you the most productive, then optimize from there. You may find out that the slowest part of your app isn’t the Linq code at all, so you’d be optimizing the wrong thing if you forbade it just because it might be slower than rolling your own loops.