Skip to content

Instantly share code, notes, and snippets.

@pauldcomanici
Created December 31, 2012 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauldcomanici/4420845 to your computer and use it in GitHub Desktop.
Save pauldcomanici/4420845 to your computer and use it in GitHub Desktop.
Empty array test script
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