$.each vs $.map on getting object keys

Benchmark created on


Preparation HTML

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

Setup

var obj = {};
    for (var i = 0; i < 1000; ++i) {
        obj['index-' + i] = Math.random(100000, 999999);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
each
var keys = [];
$.each(obj, function(k, v) {
    keys.push(k);
});
ready
map
var keys = $.map(obj, function(v, k) {
    return k;
});
ready

Revisions

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