array splicing pure vs jquery

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var crossesPos = [[317, 193], [110, 334], [390, 347], [281, 222], [307, 384], [329, 366], [230, 104], [276, 156], [173, 330], [227, 100], [397, 261], [341, 389], [233, 223], [261, 350], [267, 286]]
   
    var x = 317;
    var y = 193;
};
</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
JQuery grep
crossesPos = jQuery.grep(crossesPos,function(e) { return e[0] == 317 && e[1] == 193; },true);
pending…
Pure JavaScript for in
for(var i in crossesPos)
    {
        if(crossesPos[i][0] === x)
            if(crossesPos[i][1] === y)
            {
                crossesPos.splice(i,1);
                break;
            }
    }
pending…
JQuery each
 var position;
    jQuery.each(crossesPos, function(index){
        position = this;
        if(x == position[0] && y == position[1]){
            crossesPos.splice(index,1);
        }
    });
pending…
Pure JavaScript for
for(var i=0; i< crossesPos.length;i++)
    {
        if(crossesPos[i][0] === x)
            if(crossesPos[i][1] === y)
            {
                crossesPos.splice(i,1);
                break;
            }
    }
pending…
backwards while loop
var i = crossesPos.length;
while (i--)
    {
        if(crossesPos[i][0] === x && crossesPos[i][1] === y)
            {
                crossesPos.splice(i,1);
            }
    }
pending…
backwards for loop
for(var i=crossesPos.length-1; i>=0; i--)
{
     if(crossesPos[i][0] === x)
        if(crossesPos[i][1] === y) crossesPos.splice(i,1);          
}
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