Object acces vs array.indexOf

JavaScript performance comparison

Test case created

Info

witch is fastest

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr = [];
    var obj = {};
    for(var i=0;i<1000;++i)
    {
    arr.push( 'ele_'+i );
    obj[ 'ele_'+i ] = true;
    }
};
</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
objec access
var dummy = [];
for(var i=0;i<10;++i)
{
var tst_lab = 'ele_'+(i*99);
if( obj[tst_lab] )
dummy.push(tst_lab);
}
pending…
array.indexOf access
var dummy = [];
for(var i=0;i<10;++i)
{
var tst_lab = 'ele_'+(i*99);
if( arr.indexOf(tst_lab)!==-1 )
dummy.push(tst_lab);
}
pending…

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

Compare results of other browsers

0 comments

Add a comment