Created
December 31, 2012 15:52
-
-
Save pauldcomanici/4420845 to your computer and use it in GitHub Desktop.
Empty array test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myArray, | |
myInitialArray, | |
cleanArray, | |
continueLoopTest; | |
myInitialArray = [1,2,3,4,5,6]; | |
myInitialArray = [{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"},{a: 1, b: "2"}];; | |
cleanArray = { | |
byLength: { | |
getTitle: function () { | |
return "clean array by setting length to 0"; | |
}, | |
clean: function () { | |
myArray.length = 0; | |
} | |
}, | |
byNew: { | |
getTitle: function () { | |
return "clean array by setting array to []"; | |
}, | |
clean: function () { | |
myArray = []; | |
} | |
} | |
}; | |
function runTest() { | |
var pageTitleEl, | |
useMethod; | |
useMethod = "byNew"; | |
//useMethod = "byLength"; | |
pageTitleEl = document.getElementsByTagName("title")[0]; | |
pageTitleEl.innerText = cleanArray[useMethod].getTitle(); | |
function executeTest() { | |
var iterationNr = 0, | |
endTest; | |
endTest = Date.now() + 1000; | |
while (endTest > Date.now()) { | |
myArray = myInitialArray; | |
cleanArray[useMethod].clean(); | |
iterationNr += 1; | |
} | |
console.log(iterationNr); | |
} | |
executeTest(); | |
} | |
setTimeout(runTest, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment