$.each vs for loop vs _.each

JavaScript performance comparison

Revision 13 of this test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var testArray = [0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5];
   
    function whileGetArrayMin(array) {
        var i = 0;
        var min = array[i++];
        var len = array.length;
        var val;
   
        while (i < len) {
                val = array[i++];
                if (val < min) {
                        min = val;
                }
        }
   
        return min;
    }
   
    function whileGetArrayMinRight(array) {
        var i = array.length - 1;
        var min = array[i];
      var val;
   
        while (i > 0) {
                val = array[--i];
                if (val < min) {
                        min = val;
                }
        }
   
        return min;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
_.reduce
_.min(testArray);
pending…
_.min
_.min(testArray);
pending…
whileRight
whileGetArrayMinRight(testArray);
pending…
while
whileGetArrayMin(testArray);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment