Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is scatter name loTemp slower than scatter memvar?
Message
 
 
À
15/08/2001 22:24:49
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00544355
Message ID:
00544517
Vues:
14
Dragan,

Thanks a lot for these advices. I'll try to implement them tomorrow and see, what speed benefit I get. I already made some minor program optimization, so first I'll try them, but then I'm going to proceed with your suggestions.

Thanks.

>>Hi everybody,
>>
>>I have a program in which I scan through quite a long file (200000 recs and more) and perform some calculations. Here is the code fragment from this program:
>>
>[snipped]
>>
>>It seems to work slow. I believe, I had scatter memvar before and it worked faster, but I'm not sure. So, do you think, it's related with scatter memvar vs. scatter name or do you see some problems in this code, which may cause slowness?
>>
>>Thanks in advance.
>
>This is about Fox's internals - as usual, you better try it on a simpler test using both versions of Scatter/Gather.
>
>The speed of a thing like this may be affected by several other things, like the number of active indexes. Things I can pull out of my bag of tricks on this:
>
>- don't append blank and gather, do a SQL insert. The first way has four writes (blank value, blank index entry (entries?), real value, update indexes)
>- if dropping indexes is not an option, then don't insert into the original table, but into a cursor with compatible structure. In the end, update from the cursor. That way the indexes in the target table are updated in a single run, not record by record.
>- finally, a thing I'm experimenting with recently (actually, first real try today): generate a .prg which will run the updates. That way you'd have code for each of the sets of variable you're dealing with, thus completely dropping the long Case statement (which is now running for each m.i). In the generated .prg you may have some tests done before the .prg is generated, so they don't have to repeat for each loop.
>...gee, I had trouble explaining this to my boss, but by the end of the day I had the skeleton of it working :).
>
>Well, something like this:
>
>local lcccTown, lnRank, lcFieldsAdd
>set text to temp.prg
>set text on
>set textmerge delim to "[[,]]"   && or so, just to make it readable here
>\lparam cFile
>for i=m.lnStart to m.lnEnd step m.lnStep
>   \select (cFile)
>   \set order to [[tag(m.i)]] desc
>   \lcccTown=ccode+town
>   \lnRank=0
>   \scan for !m.llHalt
>   \     lnCount=m.lnCount+1
>   \     scatter name loTemp
>   \     with loTemp
>   do case
>      case m.i=1
>         \           lcExt='All'
>         \           lnTotal= && for all lenders in this town
>         \           if YtdNumAll>0 && Should be always >0
>         \              .MksNumAll=round((.YtdNumAll/YtdNumAll)*100,2)
>         \           else
>         \              .MksNumAll=0
>         \           endif
>         \           lcFieldsAdd='MksNumAll, RankNumAll'
>         \           if left(.lender,4)='MISC' or .lender='SELLER'
>\** Nothing
>         \           else
>         \                lnRank=m.lnRank+1
>         \                store m.lnRank to ('loTemp.Rank'+iif(mod(m.i,2)=1,'Num','Vol')+m.lcExt)
>         \           endif
>* add the rest the same wayy
>         \      endwith
>         \      select OutTable
>         \      if not seek(m.lcSearchExpr,'OutTable','ccttlndr')
>** We're now on the right record
>         \           insert into outtable ({key field here}) value (m.lcSearchExpr)
>         \      endif
>         \      gather name loTemp fields ccode, town, Lender, LndrName, county, ;
>         \         city, State, ;
>         \         YtdNumAll, YtdVolAll, PtdNumAll, PtdVolAll, ;
>         \         YtdNumPur, YtdVolPur, PtdNumPur, PtdVolPur, ;
>         \         YtdNumRef, YtdVolRef, PtdNumRef, PtdVolRef, ;
>         \         MksNumAll, RankNumAll
>         \   endscan
>      case m.i=2
>{etc etc, just repeat this for others)
>endfor
>set text off
>set text to
>
>k=0
>
>do while k<3 and not m.llHalt
>     k=m.k+1 && Increment count
>     do temp with ('curAll'+transform(m.k))
>enddo
>
>
>Using more textmerge stuff, you may even have the few things which change with m.i in arrays in the generating/calling routine, and just merge them the way we did with the tag(m.i) here, and thus do away with the case statement.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform