473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

setInterval question

Hi,

please find below a short example program that is designed to show
successive rows of cells in a browser (firefox) at regular intervals.
My problem is that as the number of cell rows increases the time
interval appears to lengthen making the running program appear to slow
down.

How can I make the cell rows appear at regular intervals without
slowing down?

Thanks in advance for any feedback.

Peter

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
<script>
var cellSize=5;
var numCells=100;
var overallWidth=(cellSize+2)*numCells;
var intervalId;
function createCell(){
var cell= document.createElement('div');
cell.style.border='1px solid #ccc';
cell.style.width=cellSize+'px';
cell.style.height=cellSize+'px';
cell.style.cssFloat='left';
cell.style.backgroundColor='#ffc';
return cell;
}
function createCellRow(){
var div=document.createElement('div');
div.style.width=overallWidth+'px';
for (var i=0; i<numCells; i++)
{ div.appendChild(createCell()); }
mainDiv.appendChild(div);
}
function start(){ intervalId=setInterval (createCellRow, 200); }
function stop(){ clearInterval(intervalId); }
function init(){
mainDiv=document.getElementById('mainDiv');
mainDiv.className='mainDiv';
mainDiv.style.width=overallWidth+'px';

var startButton=document.createElement('button');
startButton.innerHTML='Start';
startButton.onclick=start;
mainDiv.appendChild(startButton);

var stopButton=document.createElement('button');
stopButton.innerHTML='Stop';
stopButton.onclick=stop;
mainDiv.appendChild(stopButton);
}
</script>
</head>
<body onload='init()'>
<div id='mainDiv'>
</div>
</body>
</html>

May 20 '07 #1
2 2996
On May 20, 8:20 pm, pcort...@gmail.com wrote:
Hi,

please find below a short example program that is designed to show
successive rows of cells in a browser (firefox) at regular intervals.
My problem is that as the number of cell rows increases the time
interval appears to lengthen making the running program appear to slow
down.

How can I make the cell rows appear at regular intervals without
slowing down?

Thanks in advance for any feedback.

Peter

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

<script>
var cellSize=5;
var numCells=100;
var overallWidth=(cellSize+2)*numCells;
var intervalId;
function createCell(){
var cell= document.createElement('div');
cell.style.border='1px solid #ccc';
cell.style.width=cellSize+'px';
cell.style.height=cellSize+'px';
cell.style.cssFloat='left';
cell.style.backgroundColor='#ffc';
return cell;}

function createCellRow(){
var div=document.createElement('div');
div.style.width=overallWidth+'px';
for (var i=0; i<numCells; i++)
{ div.appendChild(createCell()); }
mainDiv.appendChild(div);}

function start(){ intervalId=setInterval (createCellRow, 200); }
function stop(){ clearInterval(intervalId); }
function init(){
mainDiv=document.getElementById('mainDiv');
mainDiv.className='mainDiv';
mainDiv.style.width=overallWidth+'px';

var startButton=document.createElement('button');
startButton.innerHTML='Start';
startButton.onclick=start;
mainDiv.appendChild(startButton);

var stopButton=document.createElement('button');
stopButton.innerHTML='Stop';
stopButton.onclick=stop;
mainDiv.appendChild(stopButton);}

</script>
</head>
<body onload='init()'>
<div id='mainDiv'>
</div>
</body>
</html>
Well, you do realize that the computer has its limited memory
resources? And JavaScript is, as much as it is popular, also famous
for being pretty slow. And what you do here is produce 500 div-s per
second, which is not a small job. And as you go further, the more
memory it acquires and the slower it works. You can't really do much
about it, if THIS is what you really need (although I don't see much
use from this, except for exercise)

May 21 '07 #2
On May 21, 2:09 pm, Darko <darko.maksimo...@gmail.comwrote:
On May 20, 8:20 pm, pcort...@gmail.com wrote:
Hi,
please find below a short example program that is designed to show
successive rows of cells in a browser (firefox) at regular intervals.
Myproblemis that as the number of cell rows increases the time
interval appears to lengthen making the running program appear to slow
down.
How can I make the cell rows appear at regular intervals without
slowing down?
Thanks in advance for any feedback.
Peter
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
<script>
var cellSize=5;
var numCells=100;
var overallWidth=(cellSize+2)*numCells;
var intervalId;
function createCell(){
var cell= document.createElement('div');
cell.style.border='1px solid #ccc';
cell.style.width=cellSize+'px';
cell.style.height=cellSize+'px';
cell.style.cssFloat='left';
cell.style.backgroundColor='#ffc';
return cell;}
function createCellRow(){
var div=document.createElement('div');
div.style.width=overallWidth+'px';
for (var i=0; i<numCells; i++)
{ div.appendChild(createCell()); }
mainDiv.appendChild(div);}
function start(){ intervalId=setInterval(createCellRow, 200); }
function stop(){ clearInterval(intervalId); }
function init(){
mainDiv=document.getElementById('mainDiv');
mainDiv.className='mainDiv';
mainDiv.style.width=overallWidth+'px';
var startButton=document.createElement('button');
startButton.innerHTML='Start';
startButton.onclick=start;
mainDiv.appendChild(startButton);
var stopButton=document.createElement('button');
stopButton.innerHTML='Stop';
stopButton.onclick=stop;
mainDiv.appendChild(stopButton);}
</script>
</head>
<body onload='init()'>
<div id='mainDiv'>
</div>
</body>
</html>

Well, you do realize that the computer has its limited memory
resources? And JavaScript is, as much as it is popular, also famous
for being pretty slow. And what you do here is produce 500 div-s per
second, which is not a small job. And as you go further, the more
memory it acquires and the slower it works. You can't really do much
about it, if THIS is what you really need (although I don't see much
use from this, except for exercise)
Hi, thanks for your reply.
The code I supplied just illustrates the essence of my problem. The
program I want to write does more than this. I first program I wrote
to do what I want was written with googles GWT (translates Java code
into javascript) and that program creates the cell rows at regular
intervals for many many rows without any apparent slow down; I wanted
to be able to do the same in Javascript wondering whether I could make
my program go faster but instead I am unable to even get the rows to
appear at regular intervals.
Thanks for looking at my program, do you have any suggestions? - my
GWT effort can be viewed at www.psigenics.co.uk/cellularAutomata/Main.html

May 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval...
5
by: Richard A. DeVenezia | last post by:
Is some future Mozilla going to support setInterval ( <function:function>, <interval:number> ) ? Right now it seems to be simply setInterval ( <function-text:string>, <interval:number> ) --...
1
by: Weston C | last post by:
In the course of trying to build a simple clock, I've run into a problem using the setInterval (and setTimeout) function. http://weston.canncentral.org/misc/tkeep/tkeep.html...
17
by: George Hester | last post by:
Hoe can I use setInterval where its argument is a function which also has an argument? For example I have a function change(Msg) where Msg is dynamically generated and returns nothing at this point...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
4
by: barry | last post by:
If The script below is exeuted from the onload="startit()" in the body tag everything works fine but when I remove the onload and try to execute by using the attributes.add from within the Page_Load...
3
by: Andrew Poulos | last post by:
If I have some code that's a bit like this Con = function() { this.op = 1; this.count = 0; } Con.prototype.loop = function() { this.doNext = setInterval(this.next, 100); }...
3
by: shawn | last post by:
Hi All Was trying to get this bit of code working (simplified of course) for (i=0;i<uuid_num;i++) { window.setInterval(InitMap(uuidValues), timePeriod); } Where uuid_num, uuidValues,...
1
by: jonahmason | last post by:
hi. a javascript newbie here in dire need of help. for the past 3 days i've been trying to get a script using setinterval to work but a part of the code, that executes after setinterval hits a...
2
by: shawnwperkins | last post by:
Hi Folks, I'm new to Javascript and just need a little help. I downloaded a script from Dynamic Drive's Web site and I'm trying to make a simple modification and could use some help. :) The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.