How expensive is a for loop every frame?

Hi, I was just wondering if putting a for loop in the Update() would impact my performance much? The loop runs 6 times and is used to check something.

Thanks.

Not particularly expensive. Especially if it’s only 6 iterations.

It’s a for loop and not a foreach right? And you’re not generating any garbage (temporary objects) through boxing or the ‘new BlahBlah’ operator? Because that can hurt performance over the long run. But it’s technically not the loop itself causing the performance issue.

Cheers for the reply. Nah I don’t create anything in the loop. There are 2 if statements and it changes some values in another script.

For such performance query, your best friend is the Profiler:

1 Like