Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can this be done any faster
Message
De
12/02/2006 22:47:58
 
 
À
12/02/2006 03:59:45
Suhas Hegde
Dental Surgeon
Sirsi, Inde
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 6 SP5
Database:
Visual FoxPro
Divers
Thread ID:
01095428
Message ID:
01095767
Vues:
9
Suhas,
>It is a 1 time run unless the table curropts. But still i wanted to optimise...
You should google on "premature optimization" - no problem for me,
because I like thinking about such things <g>.
But you should mention such things as well, even on the danger of getting
"backup strategy" as an answer for your business use case question ("corrupt table").

Cetin's code for unrolling reading is quite ingenuos. Still, I bet the part up to the endfor could be written
to run in less than half the time - fewer instructions can sometimes lead to superlinear gains
introduced by better "locality" (think more cache hits for an easy example),
as far less entries in vfp's variable lookup table need to be accessed.

This would not matter much, as the part afterwards should soak up about 95% of the processing time,
and the update statement alone probably is responsible for more than 85%.
Therefore the second part is much more interesting - see (part pseudo) code below .

Since I guess (Symbol + dtoc(date)) is cardinal in bhav_data, why not set a relation into bhav_data as well,
and directly replace the record in bhav_data which is automatically positioned by the scan in gainloss ?

There is a high probability that you could unroll the whole calculation into one big scan across the ordered bhav_data, dynamically resetting the arrays on symbol change. In this case save the record number in the calculation array as well and only jump directly in the table with go before and after calculation.
But without clear description of the data it is too uch of a guessing game.

HTH

thomas

UNtested from the hip:
Select symbol,Date,Close ;
   cast(0 as I) as gain, cast(0 as I) as Loss ;
   From 'bhav_data' Order By symbol, Date Into Cursor s1 nofilter
   lcSymbol = ''
   scan
      if !( symbol == m.lcSymbol )
        lcSymbol = symbol
        dimension aGainloss[1500,4] && depending on the acurracy of your mentioned max!
        copy fields s1.date, s1.gain, s1.Loss, s1.close to array aGainloss while s1.symbol == m.lcSymbol
        dimension aGainloss[_tally,4]
        skip -1
        
        for ix = 1 to alen(aGainloss,1)-1
           *-- probably a toss-up to use 1 less line but access the arrays more often
           m.diff = aGainloss[m.ix,4] - aGainloss[m.ix+1,4]
           if ( m.diff > 0 )
              aGainloss[m.ix,2] = m.diff
           else
              aGainloss[m.ix,3] = -m.diff
           endif
        endfor

        #if .f.
          *-- directly calculating via the array should be faster, 
          *-- if set relation into bhav_data cannot be used
          if ix>=14
            *-- write in 1 continued statement for less work in the interpreter
            *-- since loss and gain are divided, averaging is not needed
            rs = ( aGainloss[m.ix-13,2] + .... + aGainloss[m.ix,2] ) / ;
                 ( aGainloss[m.ix-13,3] + .... + aGainloss[m.ix,3] )  
            Update bhav_data Set RSI = (100-(100/(1+(m.rs)))) ;
                where symbol+Dtoc(Date,1) == m.lcSymbol + Dtoc(aGainloss[m.ix-14,1],1)
            *-- or a possibility to move only through the table via locate rest / found
            *-- and then replace
          endif
        #else
          *-- here should be the biggest beef, if gainloss:bhav_data is 1:1, 
          *-- set relation and replace should work great! then use the old opprach <g>
          ... other setup code
          set relation on symbol+Dtoc(Date,1) into bhav_data

          ... calculate and 
          replace RSI with (100-(100/(1+(m.rs)))) in bhav_data 
        #endif
      endif
   endscan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform