Having TALK set on in either test is going to be slower. I never have SET TALK ON unless I have a specific reason to do so.
Wilson
-----Original Message----- From: profox-admin /at/ leafe D.OT com [mailto:profox-admin@leafe.com]On Behalf Of Charlie Coleman Sent: Friday, January 31, 2003 3:24 PM To: profox /at/ leafe D.OT com Subject: Re: is this a fair test? (SCAN vs DO WHILE)
Add SET TALK OFF at the start of the code somewhere.
That is the big difference.
If you see record counts going by at the bottom of the VFP window, you know you didn't actually SET TALK OFF.
SCAN does not display the record counts, where as the DO WHILE ... construct will (unless you have SET TALK OFF).
By adding SET TALK OFF (I put it right after the CREATE CURSOR statement), the difference in speed is negligible. On my machine I got a return value of 0 in both cases.
By using SECONDS() the SCAN returned 0.125, and the DO WHILE returned 0.234. That difference can be directly attributed to the fact that VFP is interpreted vice native code compiled. The SCAN has 1 less line of code than the DO WHILE .... (e.g. the SKIP command) which takes that extra millisecond to parse and execute.
If you start adding commands inside the SCAN and DO WHILE loops (e.g. cx = addr1, etc), you'll see the speed difference really isn't that significant - e.g. the loop through 500,000 records would always be just about 0.11 secs slower - the difference would not increase with more and more commands inside the loop. Or, another way to look at it, on my machine, the DO WHILE will be about 0.22 milliseconds (.00022) slower per record than the SCAN. This is becuse of the interpreting time VFP has to spend on the SKIP.
So, historically speaking, I would say the occurrence of slow DO WHILE loops is probably more related to the SET TALK setting.
-Charlie
>#define MAXRECS 100000 >CLEAR >CLEAR ALL >CLOSE ALL >LOCAL lnLoop as Integer, lnStartTime as Datetime, lnEndTime as Datetime, >lnElapsed as Number > >CREATE CURSOR test (name c(10), addr1 c(30), addr2 c(30), city c(20), >state c(2), postal c(10)) > >FOR lnLoop = 1 TO MAXRECS > INSERT INTO test VALUES ("Ana Alicia","123 Main > St.","","Hamburg","PA","12345-6789") > INSERT INTO test VALUES ("Billy Bob","77 Holloway Drive","","West > Hollywood","CA","90210-1234") > INSERT INTO test VALUES ("Charlie Chaplin","8619 St. Charles > Lane","","Mechanicsburg","PA","17712") > INSERT INTO test VALUES ("Dee Deserata","777 East Park Blvd","PO Box > 777","Harrisburg","PA","17111") > INSERT INTO test VALUES ("Mary Poppins","Cantebury","17 Cherry Tree > Lane","London","EN","1A1 B5D") >ENDFOR > >GO TOP IN test >SELECT test >lnStartTime = DATETIME() >SCAN > && scan should be faster than DO WHILE !EOF() >ENDSCAN >lnEndTime = DATETIME() >lnElapsed = lnEndTime-lnStartTime >? "SCAN:",lnStartTime,lnEndTime,lnElapsed > >GO TOP IN test >lnStartTime = DATETIME() >DO WHILE !EOF() > SKIP > && should be slower! >ENDDO >lnEndTime = DATETIME() >lnElapsed = lnEndTime-lnStartTime >? "!EOF():",lnStartTime,lnEndTime,lnElapsed
[excessive quoting removed by server]
©2003 Wilson M. Kierstead |
|