Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SCAN vs. FOR
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00135531
Message ID:
00135669
Vues:
10
Bruce,

I've found in the past that SCAN is a little faster than FOR ... NEXT (a really tiny bit). You'll see a bigger difference if you have something like this:
SELECT table1
SCAN
  SELECT table2
  * do something
ENDSCAN

SELECT table1
FOR i=1 TO RECCOUNT()
  SELECT table2
  * do something
  SELECT table1
NEXT
The key here is that with SCAN, you don't have to SELECT the original work area each time through the loop. This is only an issue if you SELECT another work area inside the loop. Regardless of which you use, I find the difference to be minimal. I think SCAN is much more readable than FOR i=1 TO RECCOUNT(). Without a significant difference, I would use SCAN unless you have a huge loop where speed is vital.

>>WHILE is always faster than FOR because it processes a limited number of records and stops as soon as the condition is not met.
>
>I mean in exit-condition free situations -- WHILE is always slowest then. Here's a simple test in vfp5, though a great oversimplification of what I was doing in vfp6:
>
>local ntime1,ntime2,ctest,ncount
>ntime1 = seconds()
>ncount = 1
>go top
>do while !eof()
>*scan
>*for i = 1 to reccount() && table about 50,000 recs
> ncount = ncount + 1
> ctest = str(ncount) && wanted some simple activity :)
> skip 1 && not in SCAN, of course
>enddo && or for or scan
>ntime2 = seconds()
>? ntime2-ntime1
>
>A bit garbled (3 tests in 1 to condense it). Results:
>
>FOR 25.5"
>SCAN 26.8"
>WHILE 28.0"
>
>Bigger difference in original test, but you get the idea...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform