Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Whether to Use an Array or a Cursor ?
Message
De
15/08/2013 05:40:58
 
 
À
15/08/2013 02:00:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01580497
Message ID:
01580523
Vues:
57
Your code WILL run faster if you recode into less lines - vfp is an interpreter and
>>>>>IF lcRowposition $ laArray(I)=.T.
>>>>>lnRightColumnposition=GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2) && The Third last word
>>>>>lnRightColumnposition=VAL(STREXTRACT(lnRightColumnposition,')',''))
>>>>>IF lnRightColumnposition>lnLeftColumnposition
>>>>>IF TYPE(STREXTRACT(laArray(I),'(',')'))='N'
could be written as a single if-line (or filter for cursor).
>>>>>IF m.lcRowposition $ laArray(I) ;
>>>>>and VAL(STREXTRACT(GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2),')','')) >m.lnLeftColumnposition; && The Third last word
>>>>>and TYPE(STREXTRACT(laArray(I),'(',')'))='N'
But the speedup will probably not be large enough if you have a big problem. Working off a local var instead of always accessing array might be beneficient as well, but as only 3 to 5 array loads are needed again nothing helping you gain big savings if any at all.
The fastest code is that which does not run unneccesary operations - if there are certain typical table/record values you could expect and code accordingly, that might give better performance. Getting rid of the Getwordcount() in every loop by predefining if possible from the data layout would be a step forward if the first condition is true in many cases but the second or third is not...
But all in all the task seems pretty stupid - needed only because somebody created a not-too bright file format you have to parse. Sometimes writing out a different format is the better solution. You could drop down and code in C to a fll, but that only shows that the problem is the helter-skelter input needing parsing instead of having created a fixed-size lined ASCII file

>ok, Now I think that I should rewrite the code taking the Cursor instead of Array and Evaluate the total processing Time. Prehaps this would give me a correct picture.
>
>Thanks.
>Regards
>Harsh
>
>
>
>
>
>>When I get to choose between fast and flexible, I will always choose flexible, unless the speed difference is substantial.
>>
>>Both cursors and arrays are "in memory" operations, unless the cursor will have a lot of records. And cursors can be indexed. I have seen very few cases where arrays are substantially faster than cursors, but I have seen quite a few where the opposite was true.
>>
>>>Sir, by Faster I mean to ask that using a Cursor I will be able to Use LOCATE FOR or SEEK command. However, if I continue to use Array, I won't be able to Use LOCATE FOR or Seek (Perhaps these two dont work on array) and therefore, i will have to scan entire array for each Data Extraction. Instead LOCATE FOR will simply go to my required Data (and will not scan the entire Records as in case of array) and I will Pull the required information from it.
>>>
>>>From this pint of view I was thinking that What will be faster in such situation. Had it been some command like Locate FOR to work on an Array, I feel that arrays would have been more powerful.
>>>
>>>
>>>
>>>>Personally I always use cursors for this kind of manipulation, simply because I find it easier. But is it faster? I really don't know, I would guess so, but I may be wrong.
>>>>
>>>>>I am trying to some Extract Data from a Text file and preform some Manipulation on it.
>>>>>
>>>>>For Extraction of Data I have two options, 1st create a cursor using Append from abc.txt SDF and Use The Locate Command to find my Data inside and extract it.
>>>>>
>>>>>2nd Use an Array. Initially I opted the second option. Now, to extract the Data from The array I am Scaning the entire Array from top Until the record is Matched, but since the volume of Data to be extracted from ech file and the number of files are also too Large, its taking huge time for entire processing.
>>>>>
>>>>>Alternatively, now i am thinking to take the data of each file in cursor and Use LOCATE FOR Command.
>>>>>
>>>>>What would be More Faster Mode or what should I do ?
>>>>>
>>>>>Here's a small portion of my current code. Should I Continue with Array or Cursor ?
>>>>>
>>>>>
>>>>>*****************Extract Usage Charges From PS File******************
>>>>>cExit='N'
>>>>>lnRowposition=10000
>>>>>
>>>>>FOR I= 1 TO nU1 && nU1 is the Length of Array
>>>>>IF 'Usage Charges' $ laArray(I)=.T.
>>>>>lnRowposition =    VAL(GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 1)) && The second last word
>>>>>lnLeftColumnposition = GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2) && The Third last word
>>>>>lnLeftColumnposition=VAL(STREXTRACT(lnLeftColumnposition,')',''))
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDFOR
>>>>>
>>>>>FOR nFor=-1 TO 1
>>>>>lcRowposition=ALLTRIM(STR(lnRowposition+nFor))+' x'
>>>>>FOR I= 1 TO nU1
>>>>>IF lcRowposition $ laArray(I)=.T.
>>>>>lnRightColumnposition=GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2) && The Third last word
>>>>>lnRightColumnposition=VAL(STREXTRACT(lnRightColumnposition,')',''))
>>>>>IF lnRightColumnposition>lnLeftColumnposition
>>>>>IF TYPE(STREXTRACT(laArray(I),'(',')'))='N'
>>>>>nUsagecharges=VAL(STREXTRACT(laArray(I),'(',')'))
>>>>>cEXit='Y'
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDIF
>>>>>ENDIF
>>>>>IF cExit='Y'
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDFOR
>>>>>ENDFOR
>>>>>************************************************************************
>>>>>*****************Extract Balance Minimum Guarantee PS File******************
>>>>>cExit='N'
>>>>>lnRowposition=10000
>>>>>
>>>>>FOR I= 1 TO nU1
>>>>>IF 'Minimum Guarantee' $ laArray(I)=.T.
>>>>>lnRowposition =    VAL(GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 1)) && The second last word
>>>>>lnLeftColumnposition = GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2) && The Third last word
>>>>>lnLeftColumnposition=VAL(STREXTRACT(lnLeftColumnposition,')',''))
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDFOR
>>>>>
>>>>>FOR nFor=-1 TO 1
>>>>>lcRowposition=ALLTRIM(STR(lnRowposition+nFor))+' x'
>>>>>FOR I= 1 TO nU1
>>>>>IF lcRowposition $ laArray(I)=.T.
>>>>>lnRightColumnposition=GETWORDNUM(laArray(I), GETWORDCOUNT(laArray(I)) - 2) && The Third last word
>>>>>lnRightColumnposition=VAL(STREXTRACT(lnRightColumnposition,')',''))
>>>>>IF lnRightColumnposition>lnLeftColumnposition
>>>>>IF TYPE(STREXTRACT(laArray(I),'(',')'))='N'
>>>>>nBalMinimumGuarantee=VAL(STREXTRACT(laArray(I),'(',')'))
>>>>>cEXit='Y'
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDIF
>>>>>ENDIF
>>>>>IF cExit='Y'
>>>>>EXIT
>>>>>ENDIF
>>>>>ENDFOR
>>>>>ENDFOR
>>>>>************************************************************************
>>>>>
>>>>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform