Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / The [i]SPEED[/i] of different loops

Author
Message
roswell
21
Years of Service
User Offline
Joined: 17th Dec 2002
Location: United States
Posted: 7th May 2003 06:16 Edited at: 7th May 2003 06:20
I just ran across something rather interesting. I was writing a simple snippet of code to draw 360 dots of differing colors on the screen in succession, so I wrote this do loop:



Then I realized I could greatly shorten this by running a for loop instead:



This code ran instantly while the do loop took about 5 seconds. This intrigued me enough to write this code:



This last snippet simply doest the same code using 3 different loops and times them all. The results (on my machine) show the while loop took 5640 milliseconds, the for loop took 0 milliseconds, and the do loop took 5610 milliseconds. Why does it appear that the for loop completes 360 iterations 5.6 seconds faster than the while loop and the do loop? I have a feeling it has something to do with my assumptions when writing the last experiment. Can anyone explain the vast time difference with these loops?

/* You are not expected to understand this. */

Dual Athlon 2.0/1GB RAM/GeForce Ti4200-128/Win2000 Pro
Andy Igoe
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 7th May 2003 06:23
You will also notice that you cannot break the program execution whilst it is running a for..next loop as DBPro seems to go very single minded during their execution.

All I know is for..next is handled differently to other forms of looping within DB itself, and the result is preferable to the extent that if I have a while..endwhile or repeat..until loop requirement that gets used a lot within my program execution i'll replace it with something more akin to:



Pneumatic Dryll

Login to post a reply

Server time is: 2024-09-20 07:30:34
Your offset time is: 2024-09-20 07:30:34