Jquery each vs Underscore each vs For loops (v94)

Revision 94 of this benchmark created by Joe Chagan on


Description

Actually do something in the loop to prevent code from being optimized out.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js">
</script>

Setup

var arr=new Array(10000), out=[];

Test runner

Ready to run.

Testing in
TestOps/sec
Jquery each
$.each(arr, function (i, o) { out.push(o); }); 
 
ready
Underscore each
_.each(arr, function (o) { out.push(o); });
ready
For normal
for (i = 0; i<=arr.length; i++) { out.push(arr[i]); } 
 
ready
forEach
arr.forEach(function (o) { out.push(o); });
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.