I was working on a project, and this problem appeared in my head. I’m not sure that there is already such a record, but I did not find it.
Let's say if I have this:
function checks(s) { if (s.length == 4 && s[0] == "a") { //action } else { //other action } } checks("a001"); checks("else"); checks("else"); checks("else");
and this:
function checkb(b) { if (b) {
Since in any case, the if-statement will have to check once from the conditions, if the frequency of actions is known (for example, I know that the else part is executed most often). Does "non-conditions" check that the code is faster or does "not-state" checking not even affect performance? (Suppose I create a complex node.js server that has many of these types of functions.)
Add-on Question: Do most programming languages know theoretically?
I'm just wondering if this affects performance (practically or theoretically).
source share