I was testing all these different constructs using getrusage() to calculate the variations of (ru_utime + ru_stime) before and after executing them.
It turns out there's no little difference in performing the same task for similar constructs. Here are the results:printf (1.5 ± 0.5)% faster than printforeach (6.0 ± 1.0)% faster than a for loop(iterating over an indexed array of 1kk elements)for (9.0 ± 1.0)% faster than a while loopif/else (8.0 ± 1.0)% faster than a switch(tested over two cases, 6 cases, and 10 possible cases).
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?
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 if/else over switch, for over while, printf over print, foreach over for, will it eat up more RAM?