Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Argument starter - The roots of all evil
Message
From
10/09/2004 08:50:32
Walter Meester
HoogkarspelNetherlands
 
 
To
09/09/2004 13:46:51
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00938079
Message ID:
00941002
Views:
27
Hi tracy,

A few remarks on your code. I was surprise you still got a about 3 seconds difference since the most time was consumed by the WAIT WINDOW command which has nothing to do with the DO WHILE. When you comment out the wait window, the different between the two below is about 0.016 seconds (on my machine) (FOR, ENDFOR 0.500 and DO WHILE 0.516). Since with the DO WHILE you do not have to use EXIT, you could use a variable lContinue in the while clause.

Of course in these situations I'd use a SCAN WHILE lContinue which is a fraction faster as the FOR ENDFOR construct. Anyways the difference lies arround 3% or so, and that is what I would call insignificant.

Walter,
CLEAR
SET TALK OFF
SET SAFETY OFF

CREATE TABLE mytable (nvalue n(5,0), cvalue c(10))
SELE mytable
FOR i = 1 TO 50000
	APPEND BLANK
	REPLACE mytable.nvalue WITH i
ENDFOR

SELE mytable
GO TOP
mval = 0
? "FOR ENDFOR"
time1 = SECONDS()

FOR i = 1 TO RECCOUNT()
*	WAIT WINDOW "Processing "+ALLTRIM(STR(mval))+" of 50,000" NOWAIT
	DO countit WITH mval
	REPLACE mytable.nvalue WITH nvalue + 1
	IF EMPTY(mytable.cvalue)
		REPLACE mytable.cvalue WITH "TEST1"
	ELSE
		REPLACE mytable.cvalue WITH "TEST2"
	ENDIF
	IF !CHECKIT(RECNO())
		EXIT
	ENDIF
	IF mval > 999998
		EXIT
	ENDIF
	SKIP
ENDFOR

? SECONDS() - time1

SELE mytable
GO TOP
mval = 0
? "DO WHILE LOOP"
time1 = SECONDS()

lContinue = .T.
DO WHILE lContinue 
*	WAIT WINDOW "Processing "+ALLTRIM(STR(mval))+" of 50,000" NOWAIT
	DO countit WITH mval
	
	REPLACE mytable.nvalue WITH nvalue+1
	IF EMPTY(mytable.cvalue)
		REPLACE mytable.cvalue WITH "TEST1"
	ELSE
		REPLACE mytable.cvalue WITH "TEST2"
	ENDIF
	
	lContinue = CHECKIT(RECNO()) AND mval =< 999998 AND RECNO() < RECCOUNT()
	SKIP
ENDDO

? SECONDS() - time1



FUNCTION checkit
LPARAMETERS recordno
IF RECNO() <> recordno
	GOTO recordno
ENDIF
IF EMPTY(mytable.nvalue)
	? RECNO()
ENDIF
RETURN .T.

PROCEDURE countit
LPARAMETERS newval
newval = newval + 1
RETURN newval
>Changed it slightly and still the results are not drastically different in VFP8:
>
>DO WHILE: 00:00:49
>FOR/ENDFOR: 00:00:46
>
>
>CLEAR
>SET TALK OFF
>SET SAFETY OFF
>
>
>CREATE TABLE mytable (nvalue n(5,0), cvalue c(10))
>SELE mytable
>FOR i = 1 TO 50000
>	APPEND BLANK
>	REPLACE mytable.nvalue WITH i
>ENDFOR
>
>SELE mytable
>GO TOP
>mval = 0
>? "DO WHILE LOOP"
>? "START1:"
>time1 = DATETIME()
>?? time1
>DO WHILE !EOF()
>	WAIT WINDOW "Processing "+ALLTRIM(STR(mval))+" of 50,000" NOWAIT
>	DO countit WITH mval
>   REPLACE mytable.nvalue WITH nvalue+1
>	IF EMPTY(mytable.cvalue)
>		REPLACE mytable.cvalue WITH "TEST1"
>	ELSE
>		REPLACE mytable.cvalue WITH "TEST2"
>	ENDIF
>	IF !CHECKIT(RECNO())
>		EXIT
>	ENDIF
>	IF mval > 999998
>		EXIT
>	ENDIF
>   SKIP
>ENDDO
>time2 = DATETIME()
>timegone = timepassed(time1,time2)
>? "FINISH:"
>?? time2
>? "TIME ELAPSED: "
>?? timegone
>
>?
>?
>?
>
>SELE mytable
>GO TOP
>mval = 0
>? "FOR ENDFOR"
>? "START2:"
>time1 = DATETIME()
>?? time1
>FOR i = 1 TO RECCOUNT()
>	WAIT WINDOW "Processing "+ALLTRIM(STR(mval))+" of 50,000" NOWAIT
>	DO countit WITH mval
>	REPLACE mytable.nvalue WITH nvalue + 1
>	IF EMPTY(mytable.cvalue)
>		REPLACE mytable.cvalue WITH "TEST1"
>	ELSE
>		REPLACE mytable.cvalue WITH "TEST2"
>	ENDIF
>	IF !CHECKIT(RECNO())
>		EXIT
>	ENDIF
>	IF mval > 999998
>		EXIT
>	ENDIF
>	SKIP
>ENDFOR
>time2 = DATETIME()
>timegone = timepassed(time1,time2)
>? "FINISH:"
>?? time2
>? "TIME ELAPSED: "
>?? timegone
>
>
>FUNCTION checkit
>LPARAMETERS recordno
>IF RECNO() <> recordno
>	GOTO recordno
>ENDIF
>IF EMPTY(mytable.nvalue)
>	? RECNO()
>ENDIF
>RETURN .T.
>
>PROCEDURE countit
>LPARAMETERS newval
>newval = newval + 1
>RETURN newval
>
>PROCEDURE timepassed
>LPARAMETERS starttime, endtime
>timetaken = endtime - starttime
>x = ttoc( { 00:00 } + timetaken, 1)
>x = substr(x,9,2) + ':' + substr(x,11,2) + ':' + right(x,2)
>RETURN x
>
Previous
Reply
Map
View

Click here to load this message in the networking platform