Rather than call the function recursively, you might want to use setInterval
rather than setTimeout, which is what I think you are trying to
achieve...that is, run the function once per second.
I think if you run the function recursively without an "exit strategy" you
get a circular behavior which is probably why the CPU is getting hammered.
-- Josh
----- Original Message -----
From: ""Sebastián V. Würtz"" <[EMAIL PROTECTED]>
To: "jquery" <jquery-en@googlegroups.com>
Sent: Wednesday, February 13, 2008 2:23 PM
Subject: [jQuery] kill the cpu
can this code kill a cpu?
$(function() {
show_clock();
});
function showtime() {
var meses = new
Array("ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT","NOV","DIC");
var dias = new
Array("DOMINGO","LUNES","MARTES","MIERCOLES","JUEVES","VIERNES","SABADO","DOMINGO");
var d=new Date();
var seconds = d.getSeconds();
var minutes = d.getMinutes();
var hours = d.getHours();
var ampm = (hours >= 12) ? " PM" : " AM";
var week = dias[d.getDay()];
var mes = meses[d.getMonth()];
var dia = d.getDate();
var anio = d.getFullYear();
hours = ((hours > 12) ? hours - 12 : hours);
minutes = ((minutes < 10) ? "0" : "") + minutes;
seconds = ((seconds < 10) ? "0" : "") + seconds;
$('.year').text(anio);
$('.day').text(dia);
$('.month').text(mes);
$('.week').text(week);
$('span.h').text(String(hours));
$('span.minute').text(String(minutes));
$('span.seconds').text(String(seconds));
$('.ampm').text(ampm);
setTimeout('showtime()', 1000);
}
the problem is the setTimeout('showtime()', 1000);
if i uncomment the show_clock() the cpu usage is normal, but is not, the
cpu usage is at 50%+ in ie6.