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:
LINQ vs for(...) loop performance
My code:
Code (csharp):
- void LINQFind()
- {
- Debug.Log("linq find start.");
- sw.Stop();
- sw.Start();
- var trees = terrain.terrainData.treeInstances.Where(v => v.position.x > x0 && v.position.z > z0);
- newTerrain.terrainData.treeInstances = trees.ToArray();
- sw.Stop();
- Debug.Log("linq find time: " +...