I have always wondered what is best practice when checking numbers are 1 or greater.
IF($foo > 0)
OR
IF($foo >= 1)
Which one should I be using? They both appear to work the same.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When it comes to performance, you would like to use
>=instead of>.My benchmark in pseudo:
Edit: and as William in the comments suggested to time the whole for-loop, that’s exactly what happened. I added up all the times together which gave me the exact same result as timing the whole for-loop at once. So basically I did the same. (FYI. I benchmarked William his suggestion, it had the same results. Trust me, I’m an engineer)
My results:
So, when it comes to speed and you are using integers (see the great answers above!),
>=would be faster. But, consider the consequences! It’s only7msover a100.000tests. But, when you are having a couple of million records to check…edit
After a couple of more times running the benchmark, I get even bigger differences. Differences like
10,15and even20ms! Nothing was changed, apparently my processor was busy, but it is good sharing it with you guys.