short lines vs 1 long

What way of coding is faster?

    float x = methodX();
    float y = methodY();
    float z = methodZ();
    float xy = x * y;
    float xyz = xy * z;


    float xyz = methodX() * methodY() * methodZ();

I guess the second one runs faster, but you’ll never note any significant difference between them.

But as for your question of “what way of coding is faster?”… well, what block of code was faster for you to code?

Bets in this case is to find the appropriate tool. BUT!!! In this case the appropriate tool may end up being useless.

Here is what I wrote:

public class MyObject 
    public float MethodWithFloat() 
        return 0.0f;

    public void UpdateA() 
        float a = MethodWithFloat();
        float b = MethodWithFloat();
        float c = MethodWithFloat();
        float abc = a + b + c; 
    public void UpdateB() 
        float abc = MethodWithFloat() + MethodWithFloat() + MethodWithFloat();

Notice it is not a MonoBehaviour class since I wrote that in VS. Now I use the ILDASM and get for the two Updates:

.method public hidebysig instance void  UpdateA() cil managed
  // Code size       29 (0x1d)
  .maxstack  2
  .locals init ([0] float32 a,
           [1] float32 b,
           [2] float32 c,
           [3] float32 abc)
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_0007:  stloc.0
  IL_0008:  ldarg.0
  IL_0009:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_000e:  stloc.1
  IL_000f:  ldarg.0
  IL_0010:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_0015:  stloc.2
  IL_0016:  ldloc.0
  IL_0017:  ldloc.1
  IL_0018:  add
  IL_0019:  ldloc.2
  IL_001a:  add
  IL_001b:  stloc.3
  IL_001c:  ret
} // end of method MyObject::UpdateA

.method public hidebysig instance void  UpdateB() cil managed
  // Code size       23 (0x17)
  .maxstack  2
  .locals init ([0] float32 abc)
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_0007:  ldarg.0
  IL_0008:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_000d:  add
  IL_000e:  ldarg.0
  IL_000f:  call       instance float32 ConsoleApplication1.MyObject::MethodWithFloat()
  IL_0014:  add
  IL_0015:  stloc.0
  IL_0016:  ret
} // end of method MyObject::UpdateB

Conclusion, UpdateB may be faster since it has less lines and less initialization. BUT!!! This is not the code that your game will run…Nope, since this will be turned into c++ by the IL2CPP compiler and there, some optimization may be affecting the final result to a point that both end up being the same or so close, you should not be caring much about it.

So despite the fact your question is legit, the answer is

“Do not bother, it will not affect your game to the point you should spent time on it ((“whispered”) but you may want to use UpdateB)”.

Try to keep the code readable, in your case it won’t show much but there will time when you write code like this:

float distanceVertical = ( + bc.size.y / 2f) / Mathf.Sin(radians)/ Mathf.Cos (radians);

But wouldn’t this be more readable? With variable holding the name of what they are?

float tempY = + bc.size.y / 2f; 
float hypotenuse = tempY / Mathf.Sin(radians);
float distanceVertical = hypotenuse / Mathf.Cos (radians);

The codes are doing same thing but they are not same. Second one will be faster because you only declare one variable and do less procecces.