November 20th, 2006
En busca de la memoria perdida, comparativa document.getElementById vs $
Problema:
Construir 300 elementos “div” y acceder a ellos mediante la función document.getElementById y mediante la funcion $ de la librería Prototype. Comparar el uso de memoria en ambos casos y utilizando Internet Explorer 7 y Firefox 2.
Código de ejemplo:
document.getElementById()
objContainer=$("container");
for (var i=0;i<300;i++){
var div=document.createElement("div");
div.id="div_"+i;
objContainer.appendChild(div)
document.getElementById("div_"+i).innerHTML="Div "+i;
}
$
objContainer=$("container");
for (var i=0;i<300;i++){
var div=document.createElement("div");
div.id="div_"+i;
objContainer.appendChild(div)
$("div_"+i).innerHTML="Div "+i;
}
Uso de memoria (KB):
| Navegador | document.getElementById() | $ |
|---|---|---|
| Internet Explorer 7 | 16 | 12483 |
| Firefox 2.0 | 8 | 1888 |
Tags: interfaz, javascript, Navegadores, programación


4 Comments Add your own
Victor | December 8th, 2006 at 1:33
Hmm, interesante comparativa, que bueno que no he cambiado al uso de $ en lugar de getElementsById.
pecesama | January 12th, 2007 at 19:58
Orale muy interesante, definitivamente prototype es una libreria muy pesada.
Por cierto en el primero ejemplo podrias reducir mas la carga de memoria evitando el $(”container”)
Saludos
Pecesama.Net [weblog] » En busca de la memoria perdida | January 12th, 2007 at 20:06
[...] En busca de la memoria perdida, comparativa document.getElementById vs $ [...]
RetroFOX | April 13th, 2007 at 8:41
Como podes medir la memoria utilizada ?. Saludos.
Leave a Reply
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>