for vs for in performance with strings

JavaScript performance comparison

Test case created by EtnasSoft

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for normal
// Testing 'for' performance
var myArr = [ 'En', 'un', 'lugar', 'de', 'la', 'Mancha', 'de', 'cuyo', 'nombre', 'no', 'quiero', 'acordarme' ],
    myArrClone = [];

// Preparo un array de pruebas
for( var x = 0, i = myArr.length; x < i; x++ ){
    myArrClone.push( myArr[x] );
}
pending…
for in variant
var myArr = [ 'En', 'un', 'lugar', 'de', 'la', 'Mancha', 'de', 'cuyo', 'nombre', 'no', 'quiero', 'acordarme' ],
    myArrClone = [];

for( var element in myArr ){
  myArrClone.push( myArr[element] );
}
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