# Optimization: using 'if' to detect input VS updating the variable constantly

Attention Topic was automatically imported from the old Question2Answer platform.

Hi, I’m new here and would really like some help here, I have made 2 functions to get the player input, one of them uses a lot of ‘if’ statements, like you can see in the learn section of Godot, and the other one was made with the intention of not using any ‘if’ statements, I’ll add the code down below, if anyone with knowledge on the subject could help i would be thankful, does the change make any significant impact in performance?

Code 1:

``````func get_input():
rotation += get_local_mouse_position().angle() * rot_speed #1
velocity = Vector2()
if Input.is_action_pressed("move down"):
velocity.y += 1 #2
if Input.is_action_pressed("move up"):
velocity.y += -1
if Input.is_action_pressed("move left"):
velocity.x += -1
if Input.is_action_pressed("move right"):
velocity.x += 1
velocity = velocity.normalized() * speed #3
if Input.is_action_just_pressed("Fire"):
shoot()
``````

Code 2:

``````func get_input():
rotation += get_local_mouse_position().angle() * rot_speed
velocity.x = (Input.get_action_strength('move right') - Input.get_action_strength('move left'))
velocity.y = (Input.get_action_strength('move down') - Input.get_action_strength('move up'))
velocity = velocity.normalized() * speed
if Input.is_action_just_pressed("Fire"):
shoot()
``````