I've heard that If-Then statements can speed up your code:
[ Does having a lot of if statements degrade rendering speed of php? ] It can speed up your code because it can skip steps.
I also heard from one of my friends that it can slow down code from one of my friends. Consider the following pseudocode:
doStuffThatDoesntInvolveConditionals()
i = floor(random*2)
if (i==1) {
print "Heads"
doSomething()
}
else {
print "Tails"
doSomethingElse()
}
After this code is compiled and executed, the processor preloads all the stuff in doStuffThatDoesntInvolveConditionals(), but it cannot preload anything after the if-then statement because it cannot evaluate the expression in advance. Therefore, the processing speed would slow down.
- Does this preloading happen in this way?
- If so, is the amount of which it slows down your program insignificant?
- Otherwise, how does the preloading work?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire