Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which is faster: array or cursor?
Message
De
09/03/2009 19:53:31
 
 
À
09/03/2009 18:17:24
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01386748
Message ID:
01386806
Vues:
113
>>>>>>If I had 1000 values that I need to loop through (visit every node sequentially, not skip around) that needed very fast processing and they do not need disk storage... which would be faster... an array or a cursor?
>>>>>
>>>>>Cursor.
>>>>>
>>>>Wow really? I've never done any testing, but I assumed the array would be faster. I suppose a quick test with the coverage profiler would tell us for sure.
>>>>
>>>Tables are fastest
>>
>>I am not so sure here -- in the GKK Comparison tools I have an array that is upto a size of laArray[5000,5000]. This is used for the code comparison algorithm. I tried to use a cursor for this to get rid of the 5000 limit (runs out of memory) and to see if the cursor would be faster than >>the array.
>
>>The array version was considerably faster in performance -- the cursor version was far too slow to be of any value.
>
>I queried Ken Levin on Arrays and he responded that tables were the fastest.

That depends, consider the following using arrays:

IF laArray[lnNdx] = laArray[lnNdx+5]
* do something
ENDIF

Now, using a cursor (assuming that lnNdx is the current record position in the cursor):

lcValue = c_cursor.value
SKIP 5
IF lcValue = c_cursor.value
* do something
ENDIF

It is the relative comparing of array values in the structure that is considerably faster. Having to use SKIP or LOCATE is a lot slower with cursors than being able to direct access via the index.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform