Vector2 bad at performance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MadDevil57

When testing my matrix searching algoritm, i suddenly realised that using vector2 makes my algoritm slower by 10%.
In that algoritm vector2 used only when printing position to console.
When i switch to array with 2 variables it makes algoritm faster by 10-20%.
In my game there are alot of vector2, but i don’t use their methods anywhere. I just need to store somewhere x & y data, so would it be better if i switch to arrays or just 2 floats?

#running with 8x8 matrix 100000 times
for x in range(matrix.size()):
	if 1 in matrix[x]:
		return(str("found", Vector2(x,matrix[x].find(1))))
#found(7, 7)
#Time taken: 617

for x in range(matrix.size()):
	if 1 in matrix[x]:
		return(str("found", [x,matrix[x].find(1)]))
#found[7, 7]
#Time taken: 512

While I can’t answer your question specifically, I’m not aware of any particular bottleneck related to the use ofVector2. I wonder if your performance evaluation was impacted by other, unintended factors? Can you post the two variations of code you ran your performance tests on? Perhaps someone can spot something you didn’t notice.

jgodfrey | 2023-04-07 18:24

I added code under my question, thanks for suggestion

MadDevil57 | 2023-04-07 20:12