Skip to content Skip to sidebar Skip to footer

Faster Loop: Foreach Vs Some (performance Of Jsperf Is Different Than Node Or Chrome)

Which is the best way to resume the value of an array into simple true or false values. I am quite confused as jsperf is giving me VERY different results than what google chrome co

Solution 1:

from MDN

There is no way to stop or break a forEach() loop other than by throwing an exception.

using a foreach, the loop will be executed exactly 100000 times. using some, the loop stops as soon your predicate returns true.

as long as there is a chance your predicate is true, some will be more efficient

Solution 2:

After researching a bitI understood what did I do to make jsperf behave in a strange manner. I had the chrome console open when running the jsperf tests

I have seen that when you open the chrome console jsperf still logs console.log and similar messages while the scripts are executing and that is what was causing the misleading result of the tests.

Here you can see the tets after CLOSING the console window...

enter image description here

Post a Comment for "Faster Loop: Foreach Vs Some (performance Of Jsperf Is Different Than Node Or Chrome)"