Do animators cost alot of resources?

Hello. Im creating a 2D game on android. I’m having some problems with optimization. There is a player and multiple enemies with animators attached to them. Each of them have a script with these lines in void Update :

anim.SetFloat("SpeedX", myrigidbody.velocity.x);
anim.SetFloat("SpeedY", myrigidbody.velocity.y);

Then I have the animator play diffrent animations according to SpeedX and SpeedY. So I wanted to ask if this way is efficient or not ?

Get the hashes of the string names of your animator parameters and use those instead of strings.

For example:

private int speedXHash = Animator.StringToHash("SpeedX");

//...

void Update(){
       anim.SetFloat(speedXHash, myrigidbody.velocity.x);
}