main logo
Subject: RE: is this a fair test? (SCAN vs DO WHILE)
Author: "Wilson M. Kierstead"
Posted: 2003/01/31 14:27:00
 
View Entire Thread
New Search


<<Yes, but the point of a test is to come to a decision, in this case,
<<Should I use a scan or a dowhile loop for best speed?

<<And the answer is: It depends...

IMHO, it is usually always fair to state the answer is "It depends." This
generic answer is the point of doing the tests to start with.

The scan loop is designed to work with tables. The while loop is more
generic. You are right. It does depend. Things that should be checked
have to do with using rushmore or not. Not whether you have excluded a
required clause (!eof()) that would cause the while loop to fail. The topic
states "is this a fair test?" I stated it was not because eliminating the
eof() test throws something into the test that is not valid. One test run
fails while the other succeeds. Performing a while loop without the
appropriate logic to terminate the while loop changes the criteria since the
scan loop will succeed and the while loop will not succeed.

I would suggest testing both loops to skip through an indexed table using
rushmore and again, not using rushmore. All other criteria should be the
same regardless of which test is being executed.

Wilson

-----Original Message-----
From: profox-admin AT leafe DOT com [mailto:profox-admin@leafe.com]On Behalf Of
Greg Gum
Sent: Friday, January 31, 2003 2:18 PM
To: profox AT leafe DOT com
Subject: RE: is this a fair test? (SCAN vs DO WHILE)


Yes, but the point of a test is to come to a decision, in this case,
Should I use a scan or a dowhile loop for best speed?

And the answer is: It depends...

Greg

-----Original Message-----
From: Wilson M. Kierstead [mailto:wil@vfpbizapps.com]
Sent: Friday, January 31, 2003 1:13 PM
To: profox AT leafe DOT com
Subject: RE: is this a fair test? (SCAN vs DO WHILE)


It seems you are missing the point. If you are going to do a fair test
against to loop instructions, the criteria has to be the same.

You cannot reasonably compare a DO WHILE with out the check of EOF()
against the SCAN loop. The scan loop intrinsically handles the eof
check. Therefore, an apples to apples test would be as follows:

* Test While loop -Start
SELECT table
ltstart = datetime()
GO TOP
do while !EOF()
skip
enddo
? datetime() - ltstart && show number of seconds taken to skip through
entire table
* Test While loop -End

* Test Scan loop -Start
SELECT table
ltstart = datetime()
SCAN
ENDSCAN
? datetime() - ltstart && show number of seconds taken to skip through
entire table
* Test Scan loop -End

Wilson KIerstead
-----Original Message-----
From: profox-admin@leafe.com [mailto:profox-admin AT leafe DOT com]On Behalf Of
profox@cpvfug.org
Sent: Friday, January 31, 2003 9:35 AM
To: profox AT leafe DOT com
Subject: RE: is this a fair test? (SCAN vs DO WHILE)


>>> I think what makes it slower is that Fox has to evaluate !EOF() each
time.

Oh yes, I agree 100%. However, I get a laugh when some folks just don't
want to believe it. I've come into apps that took forever and changing
to SCAN loops definitely improved the speed. It was an easy target
though: there were 3 nested DO WHILE !EOF() loops and changing them to
scan with index optimizations really made the difference.

Bo -- I see what you mean now. I changed to SET TALK OFF and the
difference was practically nil.

--Michael

Michael J. Babcock, MCP
Founder/President, Central PA Visual Foxpro User Group (CPVFUG) Upcoming
meetings:
- CHUCK URWILER, February 19, 2003
- DON VAN FLEET (.Net), April 16, 2003
- and more in the works!!!
http://www.cpvfug.org
mbabcock@cpvfug.org
"Code smarter, not harder."



[excessive quoting removed by server]



 
©2003 Wilson M. Kierstead
<-- Prior Message New Search Next Message -->