Why even discuss this when it is so easy to look in the horse's mouth?
Similar questions keep coming up. Do people not know how to test this
stuff?

1. Create a loop that does Method 1 enough times so it becomes
measurable.
2. Create a 2nd loop doing Method 2 the same number of times.
3. Create a control loop that does all the same looping and set up but
doesn't
   actually do anything useful so you can subtract out that.
   (This is just for your own sanity.)
4. Compare 1 vs. 2.
5. Is it significant?  I.e., how often do you expect the code to be
executed,
   and how much does each (divide by loop iterations) individual
execution cost? 
    a. If not much, use the most maintainable code, disregarding
efficiency. 
    b. If lots, use the most efficient, even if it is a tricky, obscure
       technique. Comment for maintainability.

The program is easy to write.   The typical metrics are TIME() and
SYSTEM(9), cpu ticks.
Create one of the cases, then DUP and change the innards as needed.
Here is an example of what I mean,  comparing  
 - trim() 
 - the original method
 - WOL's STEP -1 method.

(Caveat: I used the PETE string someone else in this thread made up, but
you might loop through real representative data instead.)

      ITERATIONS = 10000000
      PETE = 'THIS}IS }}}A TEST}}}'
*
      CRT TIMEDATE(), 'Control'
      T0 = TIME() ; C0 = SYSTEM(9)
      FOR I = 1 TO ITERATIONS
         REC = PETE
      NEXT I
      C1 = SYSTEM(9) ; T1 = TIME()
      C.CTRL = (C1-C0) ; T.CTRL = (T1-T0)
      CRT TIMEDATE(), C.CTRL, T.CTRL, REC
*
      CRT TIMEDATE(), 'TRIM'
      T0 = TIME() ; C0 = SYSTEM(9)
      FOR I = 1 TO ITERATIONS
         REC = PETE
         REC< 1 > = TRIM( REC< 1 >, @VM )
      NEXT I
      C1 = SYSTEM(9) ; T1 = TIME()
      C = (C1-C0) ; T = (T1-T0)
      CRT TIMEDATE(), C, T, REC
*
      CRT TIMEDATE(), 'ORIGINAL'
      T0 = TIME() ; C0 = SYSTEM(9)
      FOR I = 1 TO ITERATIONS
         REC = PETE
         MAX = DCOUNT( REC< 1 > , @VM )
         FOR LOP=1 TO MAX
            IF LEN( REC<1,LOP>) ELSE 
               DEL REC< 1, LOP >
               MAX-= 1
               LOP-= 1
            END
         NEXT LOP
      NEXT I
      C1 = SYSTEM(9) ; T1 = TIME()
      C = (C1-C0) ; T = (T1-T0)
      CRT TIMEDATE(), C, T, REC
*
      CRT TIMEDATE(), 'WOL'
      T0 = TIME() ; C0 = SYSTEM(9)
      FOR I = 1 TO ITERATIONS
         REC = PETE
         MAX = DCOUNT( REC, @VM )
         FOR LOP = MAX TO 1 STEP -1
            IF LEN( REC< 1, LOP > ) ELSE DEL REC< 1, LOP >
         NEXT LOP
      NEXT I
      C1 = SYSTEM(9) ; T1 = TIME()
      C = (C1-C0) ; T = (T1-T0)
      CRT TIMEDATE(), C, T, REC


>RUN CDS.BP TRIMTEST
13:34:41 25 MAR 2004          Control
13:34:50 25 MAR 2004          9550      9.82      THIS}IS }}}A TEST}}}
13:34:50 25 MAR 2004          TRIM
13:35:32 25 MAR 2004          39490     41.5798   THIS}IS }A TEST
13:35:32 25 MAR 2004          ORIGINAL
13:38:53 25 MAR 2004          176770    200.5888  THIS}IS }A TEST
13:38:53 25 MAR 2004          WOL
13:41:29 25 MAR 2004          153400    156.3228  THIS}IS }A TEST
>


No brainer: Use TRIM().
QED,
cds
--
u2-users mailing list
[EMAIL PROTECTED]
http://www.oliver.com/mailman/listinfo/u2-users

Reply via email to