What's faster?

Let’s say we have a gameobject with 2 scripts attached.
One script would have Velocity value that is calculated with rigidbody.velocity.magnitude. The other script needed that exact value. What would be faster - using getcomponent to get that value or declaring a variable and calculating the velocity with rigidbody.velocity.magnitude? Is getcomponent slow?

If you cache your rigidbody component, you get the same.

Using GetComponent each frame is not recommended but if you cache it then it is like usng a variable.

rigidbody variable is actually a property and is slightly slower so if you cache that you end up with the same as the above.

i would say rigidbody.velocity.magnitude… since you already have a reference to the rigidbody component, there is no overhead. The overhead would be creating the reference to the other component. There is no need for this, and even if there was a need, it would still be wise to reference the singleton instead of creating another variable to store the exact same information in two places. It makes no sense to create two copies of the same information. Use the singleton rigidbody.velocity.magnitude.