I write and search fall down code for 2d game. Both codes run is Update function. Which one of the more performance? These codes runs 3-4 active game objects (attached scripts) in gameplay.
First one is;
number.transform.Translate (new Vector2 (0, Global.globalInstance.objectDropSpeed) * Time.deltaTime);
They are probably both very close to the same cost and will be an utterly insignificant amount of time if you’re just running it a few times a frame. You could setup a test where you run each bit of code within a for loop of hundreds of thousands of iterations, but the difference would only show up at that scale.
In general, write code based on clarity/correctness first and the only worry about optimizing when the profiler tells you that code is actually a bottleneck.
In this case I guess the first one is better, less variables equals less memory to allocate. But if you need to access the fall speed later to another calculation, the second way is better.
But a tip in this case: To optimize the performance is better to avoid calling construction methods (like new Vector3() or new Vector2()) in the update because it will take up more memory and give more work to the garbage collector.
=]