Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Slow LOCATE command in _Assign method
Message
From
12/05/2010 13:23:44
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
12/05/2010 03:16:10
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01463679
Message ID:
01464323
Views:
64
>Perhaps I should clarify what I meant by "implicit loop" -- the question was if the condition specified in the FOR clause would be evaluated multiple times (as if in a loop). In the worst case where the search can't be optimized, wouldn't it be equivalent to iterating sequentially through the list? If this is indeed the case then this might explain the apparent difference in speed between using memory variable and property of an object.
>
>>LOCATE has nothing to do with loops. It simply finds the first matching record.
>>
>>>Is there an implict loop with LOCATE?

His search was optimized. Normally there is a slight difference between a Of course there has to be looping code - inside VFP - to iterate through the filtered records. There is also 'looping' code to iterate the class hierarchy for the object.property. This secondary loop is supposed to be short-circuited by WITH and it is also short-circuited by first assigning the property to a memory variable.

The differences are small, but suggest the internal operations. This code:

lotest = CREATEOBJECT("empty")
addproperty(LOTEST,"membername","MCINTYRE")

FOR x = 1 TO 100000
ENDFOR x

A=SECONDS()
FOR X = 1 TO 1000
LOCATE
LOCATE FOR UPPER(SURNAME)= "MCINTYRE"
ENDFOR X
?"NO PROPERTY",SECONDS()-M.A

A=SECONDS()
FOR X = 1 TO 1000
LOCATE
LOCATE FOR UPPER(SURNAME)= LOTEST.MEMBERNAME
ENDFOR X
?"OBJECT.PROPERTY",SECONDS()-M.A

A=SECONDS()
WITH LOTEST
FOR X = 1 TO 1000
LOCATE
LOCATE FOR UPPER(SURNAME)= .MEMBERNAME
ENDFOR X
ENDWITH
?"WITH .PROPERTY",SECONDS()-M.A

A=SECONDS()
M.VAR = LOTEST.MEMBERNAME
FOR X = 1 TO 1000
LOCATE
LOCATE FOR UPPER(SURNAME)= M.VAR
ENDFOR X
?"MEMVAR",SECONDS()-M.A


Gives the following output

NO PROPERTY 0.162
OBJECT.PROPERTY 0.115
WITH .PROPERTY 0.691
MEMVAR 0.051

Second run:
NO PROPERTY 0.088
OBJECT.PROPERTY 0.055
WITH .PROPERTY 0.720
MEMVAR 0.050

Notice that the object approaches are not even close to each other in either run. I'm surprised that the WITH is so much slower. I'm happy the memvar beats the literal, how often do we get to search for a literal?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform