- Home /
Looping through vector3 list slow
So today while messing around in Unity I ran into something that I thought was strange. I have some code that generates a list of ~40k vector3 points along with some other things that is blazing fast. I know its fast because when I just have it print the size of the list to the console it happens almost immediately after I hit the play button. Now when I loop through the entire list and have it print out each Vector3, it takes much longer.
My loop is set up as such...
foreach (var vert in verticesList)
{
print("Vertex " + ind + ": " + vert.x * 105 + "," + vert.y * 105+ "," + vert.z * 105);
ind++;
}
Any advice on why this increase run time by so much would be very much appreciated.
Answer by whydoidoit · Feb 17, 2014 at 03:41 AM
Printing requires a complete stack trace for each line (for debugging purposes) - that is a very slow operation. Don't print it and the loop will be fast.
What @whydoidoit said - 40k debug log entries is very slow compared to just iterating the list.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133744im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Saving and applying an array of Vector3 velocities on an array of GameObjects 1 Answer
C# List looping Vector3's 2 Answers
Having Trouble with Vector3.Angle 1 Answer