$.each vs Array.forEach

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var arr = [],
        i = 0,
        ilen = 10000,
        callbackForEach = function(v) {
        return parseInt(v);
        },
        callbackEach = function(i, v) {
        return parseInt(v);
        }
        
        
        
        
        
        
        
    for (; i < ilen; i++) {
      arr[i] = Math.random() * 1000;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
$.each
$.each(arr, callbackEach)
ready
Array.forEach
arr.forEach(callbackForEach)
ready

Revisions

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