In a question it was discussed on how jQuery and native JS would perform against each other.
While of course the vanilla solution performs a lot faster because it does not process the whole array I proposed the usage of Array.filter
which I was pretty confident would be at least faster than $.grep
.
Surprisingly after adding it to the test I was taught a lesson: Testsuite
Edgecases of course have a different outcome.
Anyone having an idea why $.grep
is supposed to be over 3 times faster than the native method Arrray.filter
?
Edit: I modified the test to use the filter shim from MDN and the results are pretty interesting:
- Chrome: Even MDN shim is faster than the native method, jQuery way ahead
- Firefox: shim a bit slower than native method, jQuery way ahead
and finally a result like i was hoping it to see in
- Internet Explorer:
native method is the fastest, then jQuery, shim is slowest (perhaps this is just the result of IEs rather weak JS-engine...)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…