Arielladog
07-02-2004, 07:58 PM
Hey guys,
It's probably easier to show you the test cases than explain, but I'll go ahead and try.
In IE, if I create Objects in an array (with new Object()) and add them onto the array, the time seems to depend on how many objects I previously created. For example, if I create 5000 objects, the time it takes is like 313 ms, then on the next run 859 ms, then 1300 ms, etc.... until I null out the references.
However, doing a similar test with DOM nodes and adding them to the Document is a constant time operation in IE.
I mozilla, they're both constant time operations (as they should be).
DOes anyone have an explanation for this?
testObjects.html:
<html>
<head>
</head>
<script>
var objArray = new Array();
function createDummyObjects()
{
var startT = new Date().getTime();
var start = objArray.length;
for (var i=start; i<start+5000; i++)
{
objArray.push(new Object());
objArray[i].prop1=new Object();
objArray[i].prop2="something";
objArray[i].prop3=new Array();
}
alert(new Date().getTime() - startT);
}
function removeDummyObjects()
{
objArray = null;
objArray = new Array();
}
</script>
<body>
<button onclick="createDummyObjects()">Create Them</button>
<button onclick="removeDummyObjects()">Remove Them</button>
</body>
</html>
testDOM.html:
<html>
<head>
</head>
<script>
var objArray = new Array();
function createDummyObjects()
{
var startT = new Date().getTime();
for (var i=0; i<2000; i++)
{
var div = document.createElement("div");
div.appendChild(document.createTextNode("Yah"));
document.body.appendChild(div);
}
alert(new Date().getTime() - startT);
}
function removeDummyObjects()
{
while(document.body.hasChildNodes()){
document.body.removeChild(document.body.lastChild)
}
var button = document.createElement("button");
button.appendChild(document.createTextNode("Create Them"));
button.onclick = createDummyObjects;
document.body.appendChild(button);
var button = document.createElement("button");
button.appendChild(document.createTextNode("Remove Them"));
button.onclick = removeDummyObjects;
document.body.appendChild(button);
}
</script>
<body onload="removeDummyObjects()"></body>
</html>
aDog :cool:
It's probably easier to show you the test cases than explain, but I'll go ahead and try.
In IE, if I create Objects in an array (with new Object()) and add them onto the array, the time seems to depend on how many objects I previously created. For example, if I create 5000 objects, the time it takes is like 313 ms, then on the next run 859 ms, then 1300 ms, etc.... until I null out the references.
However, doing a similar test with DOM nodes and adding them to the Document is a constant time operation in IE.
I mozilla, they're both constant time operations (as they should be).
DOes anyone have an explanation for this?
testObjects.html:
<html>
<head>
</head>
<script>
var objArray = new Array();
function createDummyObjects()
{
var startT = new Date().getTime();
var start = objArray.length;
for (var i=start; i<start+5000; i++)
{
objArray.push(new Object());
objArray[i].prop1=new Object();
objArray[i].prop2="something";
objArray[i].prop3=new Array();
}
alert(new Date().getTime() - startT);
}
function removeDummyObjects()
{
objArray = null;
objArray = new Array();
}
</script>
<body>
<button onclick="createDummyObjects()">Create Them</button>
<button onclick="removeDummyObjects()">Remove Them</button>
</body>
</html>
testDOM.html:
<html>
<head>
</head>
<script>
var objArray = new Array();
function createDummyObjects()
{
var startT = new Date().getTime();
for (var i=0; i<2000; i++)
{
var div = document.createElement("div");
div.appendChild(document.createTextNode("Yah"));
document.body.appendChild(div);
}
alert(new Date().getTime() - startT);
}
function removeDummyObjects()
{
while(document.body.hasChildNodes()){
document.body.removeChild(document.body.lastChild)
}
var button = document.createElement("button");
button.appendChild(document.createTextNode("Create Them"));
button.onclick = createDummyObjects;
document.body.appendChild(button);
var button = document.createElement("button");
button.appendChild(document.createTextNode("Remove Them"));
button.onclick = removeDummyObjects;
document.body.appendChild(button);
}
</script>
<body onload="removeDummyObjects()"></body>
</html>
aDog :cool: