Ver Mensaje Individual
  #6 (permalink)  
Antiguo 12/10/2012, 09:28
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Medir tiempo que tarda en ejecutarse una funcion

No sé exactamente el objeto, algo asi
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. </head>
  7. <div id="ms"></div>
  8. <script type="text/javascript">
  9. //<![CDATA[
  10. function tiempo(){
  11. var i = 1;
  12.  
  13. while (i < 10) {
  14. var date1 = new Date();
  15. var milisegundos1 = date1.getTime();
  16. //  alert('x'); --> aqui tu función
  17. var date2 = new Date();
  18. var milisegundos2 = date2.getTime();
  19. var diff_mseg = milisegundos2 - milisegundos1;
  20. document.getElementById('ms').innerHTML += 'bucle ' + i + ': ' + diff_mseg + ' milisegundos<br \/>';
  21. i++
  22. }
  23. }
  24. setInterval('tiempo()',1000);
  25. //]]>
  26.  
  27. </body>
  28. </html>
la función se repite constantemente cada 1 segundo, pero el bucle NO es infinito.
bajale el valor del setTimeout para reducir el tiempo.
el alert debe ser reemplazado por tu función

con Date() volvemos a tomar los milisegundos para calcular la diferencia


SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.