title: Performance: if else vs switch, while vs for, for each vs for, print vs printf
body: <p>I was testing all these different constructs using <code>getrusage()</code> to calculate the variations of <code>(ru_utime + ru_stime)</code> before and after executing them.<br>It turns out there's no little difference in performing the same task for similar constructs. Here are the results:<br><code>printf</code> (1.5 &plusmn; 0.5)% faster than <code>print</code><br><code>foreach</code> (6.0 &plusmn; 1.0)% faster than a <code>for</code> loop(iterating over an indexed array of 1kk elements)<br><code>for</code> (9.0 &plusmn; 1.0)% faster than a <code>while</code> loop<br><code>if/else</code> (8.0 &plusmn; 1.0)% faster than a <code>switch</code>(tested over two cases, 6 cases, and 10 possible cases).<br></p>
  
  <p>So I was wondering, do these differences really matter? If we use all the most efficient such constructs in our code, will it make some difference? Maybe 6%, 8% there, 9% or 10% there, summed up will change the efficiency of our code?<br>Or will these differences nonetheless be not noticeable, I mean the response of the server to requests will almost not vary? Also, if we use <code>if/else</code> over <code>switch</code>, <code>for</code> over <code>while</code>, <code>printf</code> over <code>print</code>, <code>foreach</code> over <code>for</code>, will it eat up more RAM?</p>