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

LINQ vs for(...) loop

$
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:
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: " +...

LINQ vs for(...) loop

Viewing all articles
Browse latest Browse all 1466670

Trending Articles



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