@rexfordkelly pastebin.com/q9pRNKwv This gives:Loop: loopForIndexed: 0.120ms Loop: loopAnonIndexed: 0.090ms Loop: useForEach: 0.070ms Loop: loopForEach: 0.045ms loopForIndexed250loopAnonIndexed500useForEach2000loopForEach1 which suggests useforeach is more than 4 times faster than anonindexed which is second fastest.
@rexfordkelly Hmm. We do get different results tho. I have it setup like this: var j = 0;string += "loopForIndexed"; console.time("Loop: loopForIndexed"); loopForIndexed(sampleSize); console.timeEnd("Loop: loopForIndexed"); string += j; for each benchmark. In the loops there j++; added to noop and inside the for loop.
@rexfordkelly the declarations were made outside of the benchmarks in the second case. Seems like the useForeach is around 4 times faster than any other and the last is not even running. Only thing added inside the benchmarks was j++; Might be that last one is running somehow async tho.
@rexfordkelly loopForIndexed times run: 500 loopAnonIndexed times run: 500 useForEach times run:1000 times run:loopForEach times run: 1. I switched to counting how many iterations were done. Benchmarks are as follow : Loop: loopForIndexed: 0.115ms Loop: loopAnonIndexed: 0.130ms Loop: useForEach: 0.050ms Loop: loopForEach: 0.065ms
well I put a string += "e"+e+"i"+i+"c"+c; in the noop function and string +="loopname"; to each of those function calls then last console.log(string); I get all the function names followed by nothing. Then after useForEach I get 3.9million characters. Then after that the loopForEach but nothing concatenated.
@rexfordkelly well only loop running in snippets is the useforeach which gets run about 1000*1000 times. I put a string to test those loops and concatenated, only that loop produces about 3.9million characters while others do nothing.
I just did console log in the loopAnonIndexed inside the "anonymous" loop function and there's really just one console log. On the other hand the console.log adds about 4 times the execution time of without console.log. Those loops don't work in snippets?
You haven't met employer that changes it's mind to what they want the code to do? Wow, but point taken. I'm don't code like you describe me to code. That was just an example trying to help out with the actual problem
You should at least explain to me how using a while while fetching query row's is going to change my thinking for the worse and make my code " slower, poorlycoded and lessreliable"
What is your problem it's way more readable when you have to read thousands of lines of queries and php and don't have to look for that one that doesn't have while