><snip>
>>If you do not have to use CONTINUE, then:
>>SCAN it is faster, and for a single field LOOKUP() it is 100% faster
>>YOU CAN CHANGE
>>
>>LOCATE XXXX
>>IF FOUND()
>> YYYY
>>ENDIF
>>
>>WITH
>>
>>SCAN XXXX
>> YYYYY
>> EXIT
>>ENDSCAN
>>* ATTENTION, ENDSCAN restore the SCAN workarea
>>
>>OR
>>
>>SCAN XXXX
>> EXIT
>>ENSCAN
>>IF !EOF()
>> YYYY
>>ENDIF
>>
>>or for a single field
>>
>>IF LOOKUP() AND !EOF()
>> YYYY
>>ENDIF
>>
>
>Hi Fabio. Any idea why there would be this difference in speed between these methods?
>
>Ciao!
Of course, only hypothesis:
- LOCATE it demands of the additional operations
because VFP have to store the expression and status
for execute a eventual successive
CONTINUE operation;
- SCAN it does not have to make this job additional;
honestly this explanation me seems insufficient to explain all,
SCAN has an overload which had to the control of endscan.
- LOOKUP it is the true force of VFP, the inner code of search,
it is effectively 2x faster than LOCATE;
an explanation part is in the fact that LOCATE/SCAN must revalue
all the expression for every record, LOOKUP use a C data driver code (?)
( get the parm2 and compare with the field=parm3 )
An other small improvement can be obtained adding NOOPTIMIZE
(if it is sure that VFP cannot optimize the FOR),
in this case VFP jumps all the phase of analysis for the optimization.
If it is present WHILE, NOOPTIMIZE it is not required,
because with WHILE VFP it cannot optimize the FOR.
Ciao
Fabio