Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which is faster?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00903686
Message ID:
00903991
Views:
12
Dawa, if you open/close the table every time, the GO BOTTOM or not GO BOTTOM is practically insignificant.

Hovewer, LOCATE it is superfluous.
*whoisfaster.prg
CLEAR 
DELETE FILE table1.*
SET ESCAPE ON 
CREATE TABLE table1 FREE (field1 I) 
INDEX ON field1 TAG field1 of table1.cdx ASCENDING
* if you use a DESCENDING index, you can save some microsecond
*INDEX ON field1 TAG field1 of table1.cdx DESCENDING


LOCAL lcCaption
m.lcCaption = _vfp.Caption 
FOR i = 1 TO 2^20
	*_SCREEN.Caption = TRANSFORM(i)  && DO NOT USE _vfp, IT IS A COM TURTLE
	INSERT INTO table1 VALUES (RAND()*1000000000) 
NEXT 
USE
_vfp.Caption = m.lcCaption 

* startup
FOR i = 1 TO 100
	=approach1() 
NEXT 

LOCAL lnCount
m.lnCount = 2^13

*Approach 1
?"Approach 1"
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach1() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:


?"Approach 2"
*Approach 2
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach2() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:


?"Approach 2 Best"

*Approach 2
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach2Best() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:

?"Approach 2 Best"

*Approach 2
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach2Best() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:


?"Approach 2"
*Approach 2
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach2() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:


*Approach 1
?"Approach 1"
m.lnSeconds = SECONDS() 
FOR i = 1 TO m.lnCount
	=approach1() 
NEXT 
?? SECONDS() - m.lnSeconds 
* Result:

DELETE FILE table1.*

FUNCTION approach1
	PRIVATE lnMax
	USE table1 ORDER field1
	GO BOTTOM
	STORE table1.field1 TO lnMax
	USE
	RETURN m.lnMax 
ENDFUNC

FUNCTION approach2
	PRIVATE lnMax
	USE table1 ORDER field1 DESCENDING
	LOCATE
	STORE table1.field1 TO lnMax
	USE
	RETURN m.lnMax 
ENDFUNC

FUNCTION approach2best
	PRIVATE lnMax
	USE table1 ORDER field1 DESCENDING
	STORE table1.field1 TO lnMax
	USE
	RETURN m.lnMax 
ENDFUNC
Previous
Reply
Map
View

Click here to load this message in the networking platform