LINQ声明不是“的foreach”循环更快 [英] LINQ statement faster than 'foreach' loop

查看:108
本文介绍了LINQ声明不是“的foreach”循环更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个网格渲染经理认为这将是一个好主意,把所有使用相同着色器的网格,然后使这些将我在那着色器通。

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 will I'm in that shader pass.

我目前使用foreach循环,但不知道是否利用LINQ的可能给我的性能提升?

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

推荐答案

为什么要LINQ是更快?它还使用循环内部。

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

大部分的时间,LINQ会有点慢,因为它引入了开销。如果你在意性能,请不要使用LINQ。因为你想更好更短的可读性和可维护性code使用LINQ。

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.

这篇关于LINQ声明不是“的foreach”循环更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆