Iterating for-loop normal and undefined

Benchmark created by Enzo on


Setup

for (var items = 9999,arr=[],obj={}, arr2=[], obj2={}, i=0, arr3=[]; i<items; ++i) {
        arr.push(true);
        obj[i]=true;
        delete arr3[arr3.push(true)-1];
    }
    
    arr2[items-1] = true;
    obj2[items-1] = true;

Test runner

Ready to run.

Testing in
TestOps/sec
Array
for (i=0; i<items;i++) {
        if (arr[i] !== undefined)
                arr[i];
}
ready
Array empty
for (i=0; i<items;i++) {
       if (arr2[i] !== undefined)
                arr2[i];
}
 
ready
Object
for (i in obj)
        obj[i];
ready
Object empty
for (i in obj2)
        obj2[i];
ready
Array for-in
for (i in arr) {
        if (arr[i] !== undefined)
                arr[i];
}
ready
Array for-in undefined
for (i in arr) {
        if (arr[i] !== undefined)
                arr[i];
}
ready
Array removing
for (i=0; i<items;i++) {
        if (arr3[i] !== undefined)
                arr3[i];
}
ready

Revisions

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