for vs for in performance with strings

Benchmark created by EtnasSoft on


Test runner

Ready to run.

Testing in
TestOps/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] );
}
ready
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] );
}
ready

Revisions

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