Array-range: 1.9 & 2.0 .grep VS John Resigs arrayRemove

JavaScript performance comparison

Revision 3 of this test case created by tomByrer

Info

v3: jQuery .grep() may have improved the last few versions. The newest versions are compared to an old still-popular version (1.4.2). v1.7.2 seemed to be the same speed as 1.9, so it was thrown out.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>var $14 = jQuery.noConflict();</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>var $19 = jQuery.noConflict();</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>var $20 = jQuery.noConflict();</script>
<script>
Benchmark.prototype.setup = function() {
    function arrayRemove(array, from, to) { //John Resig's Array Remove
      var rest = array.slice((to || from) + 1 || array.length);
      array.length = from < 0 ? array.length + from : from;
      return array.push.apply(array, rest);
    };
   
    var arr = [1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1];
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
arrayRemove
arrayRemove(arr, 4, 9);
pending…
$.grep 1.4
$14.grep(arr, function(v, i){ return(i<4 && i>9) } );
pending…
$.grep 1.9
$19.grep(arr, function(v, i){ return(i<4 && i>9) } );
pending…
$.grep 2.0
$20.grep(arr, function(v, i){ return(i<4 && i>9) } );
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:

1 comment

tomByrer (revision owner) commented :

IE8 will run v2.0.0, but gives this error on load: Object doesn't support this property or method.

Add a comment