-1

I've been working with python and pygame recently, and I was wondering, is it more efficient, processor/RAM wise to use if x != y: x = y or x = y in my main loop? I understand that the difference would be so small that it would make next to no difference, but I am still curious.

  • Not sure what you're getting at here... the first statement has 2 components, an if statement and an assignment, the second statement just has the same assignment. So, wouldn't it make sense that the second is faster? – Chris Sprague Jun 17 '16 at 21:01
  • Not necesarily: aren't comparisons faster than assignments? Then if "almost every time" x == y then it'd probably faster to check first, wouldn't it? – Dleep Jun 17 '16 at 21:03

1 Answers1

0

x = y doesn't require a comparison, and a comparison can be resource costy sometimes.

So I would say that just x = y is better.

Yotam Salmon
  • 2,400
  • 22
  • 36