Quantcast
Channel: Unity Forum
Viewing all articles
Browse latest Browse all 1466670

LINQ vs for(...) loop performance

$
0
0
I have a terrain with 30k tree. I want to copy from one to another. I've used for(...) loop and it took ~21s. When i use LINQ, it only took ~7ms.
My code:
Code (csharp):
  1.  
  2. void LINQFind()
  3.     {
  4.         Debug.Log("linq find start.");
  5.         sw.Stop();
  6.         sw.Start();
  7.         var trees = terrain.terrainData.treeInstances.Where(v => v.position.x > x0 && v.position.z > z0);
  8.         newTerrain.terrainData.treeInstances = trees.ToArray();
  9.         sw.Stop();
  10.         Debug.Log("linq find time: " +...
LINQ vs for(...) loop performance

Viewing all articles
Browse latest Browse all 1466670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>