Thought I'd have a go at something a bit different so I came up with a
recursive routine (CHECK.LIST). I used a simple list of 5000 integers
and filtered evens out as my test. The recursion basically splits the
list in half until it's smallish, then processes CNT to 1 step -1. It
didn't produce dramatic time savings until I used dimensioned arrays to
quickly split the source list. I used the best suggestions from all the
previous posts to compare a few different methods to gauge how each
performs.


TEST.LIST.PROCESSING

 

List has 5000 entries

1]2]3]4]5]6]7]8]9]10]11]12]13]14]15]16]17]18]19]20]21]22]23]24]25]26]27]
28]...  
 

Evens filtered with DELETE, elapsed time is 313ms

1]3]5]7]9]11]13]15]17]19]21]23]25]27]29]31]33]35]37]39]41]43]45]47]49]51
]53]55] 
 

Filtered with DEL, elapsed time is 453ms

1]3]5]7]9]11]13]15]17]19]21]23]25]27]29]31]33]35]37]39]41]43]45]47]49]51
]53]55] 
 

DELETE using CNT to 1 STEP -1, elapsed time is 578ms

1]3]5]7]9]11]13]15]17]19]21]23]25]27]29]31]33]35]37]39]41]43]45]47]49]51
]53]55] 
 

Filtered using second list, elapsed time is 547ms

1]3]5]7]9]11]13]15]17]19]21]23]25]27]29]31]33]35]37]39]41]43]45]47]49]51
]53]55] 
 

Split lists recursively & filter small lists, elapsed time is 16ms

1]3]5]7]9]11]13]15]17]19]21]23]25]27]29]31]33]35]37]39]41]43]45]47]49]51
]53]55]


Regards,

Eric Y. Neu
Sr. Programmer Analyst
Zetron, Inc.
425.820.6363 x271
www.zetron.com
 

ps are attachements allowed on this list server, wasn't sure so I posted
the routines inline



****************************************
* Program: TEST.LIST.PROCESSING        *
* Purpose: test list handling methods  *
* By: EYNeu - 07/12/12                 *
****************************************

* build a list of integers & time filtering evens
* from the list using various methods and techniques

* --- build a list of integers to process
TOTCNT = 5000
LIST = ''
FOR I = 1 TO TOTCNT
LIST<-1>=I
NEXT I
SAVELIST = LIST

PRINT 'List has ':TOTCNT:' entries'
PRINT LIST[1,75]:'...'

* --- DELETE is baseline method
CNT  = TOTCNT
LIST = SAVELIST
BT   = SYSTEM(12)
FOR I = 1 TO CNT
 IF LIST<I>/2 = INT(LIST<I>/2) THEN
   LIST = DELETE(LIST,I)
   I -= 1
   CNT -= 1
 END
NEXT I
ET = SYSTEM(12)

PRINT
PRINT 'Evens filtered with DELETE,':
PRINT ' elapsed time is ':ET-BT:'ms'
PRINT LIST[1,79]

* --- try DEL instead
CNT  = TOTCNT
LIST = SAVELIST
BT   = SYSTEM(12)
FOR I = 1 TO CNT
 IF LIST<I>/2 = INT(LIST<I>/2) THEN
   DEL LIST<I>
   I -= 1
   CNT -= 1
 END
NEXT I
ET = SYSTEM(12)

PRINT
PRINT 'Filtered with DEL,':
PRINT ' elapsed time is ':ET-BT:'ms'
PRINT LIST[1,79]

* -- baseline method working from cnt to 1
CNT  = TOTCNT
LIST = SAVELIST
BT   = SYSTEM(12)
FOR I = CNT TO 1 STEP -1
 IF LIST<I>/2 = INT(LIST<I>/2) THEN
   LIST = DELETE(LIST,I)
 END
NEXT I
ET = SYSTEM(12)

PRINT
PRINT 'DELETE using CNT to 1 STEP -1,':
PRINT ' elapsed time is ':ET-BT:'ms'
PRINT LIST[1,79]

* --- filter using a second list
CNT   = TOTCNT
LIST  = SAVELIST
LIST2 = ''
BT    = SYSTEM(12)
FOR I = 1 TO CNT
 IF LIST<I>/2 # INT(LIST<I>/2) THEN
   LIST2<-1> = LIST<I>
 END
NEXT I
ET    = SYSTEM(12)
LIST  = LIST2
LIST2 = ''

PRINT
PRINT 'Filtered using second list,':
PRINT ' elapsed time is ':ET-BT:'ms'
PRINT LIST[1,79]

* --- recursively split list and filter smaller lists
LIST = SAVELIST
BT   = SYSTEM(12)
CALL CHECK.LIST(LIST)
ET   = SYSTEM(12)

PRINT
PRINT 'Split lists recursively & filter small lists,':
PRINT ' elapsed time is ':ET-BT:'ms'
PRINT LIST[1,79]






SUBROUTINE CHECK.LIST(LIST)

****************************************
* Program: CHECK.LIST                  *
* Purpose: Recursive list processor    *
* By: EYNeu - 07/12/12                 *
****************************************

LISTMAX = 100
CNT = DCOUNT(LIST,@AM)

IF CNT > LISTMAX THEN

  MID = INT(CNT/2)

  * -- first go at splitting lists
  * -- too much overhead in building split lists this way
  *FIRSTHALF = ''
  *FOR I = 1 TO MID
  *  FIRSTHALF<-1> = LIST<I>
  *NEXT I
  *CALL CHECK.LIST(FIRSTHALF)
  *
  *SECONDHALF = ''
  *FOR I = MID+1 TO CNT
  *  SECONDHALF<-1> = LIST<I>
  *NEXT I
  *CALL CHECK.LIST(SECONDHALF)

  * -- second go at splitting a list
  * -- dimensioned arrays are handy for a quick split
  FIRSTHALF = ''
  SECONDHALF = ''
  DIM LISTARRAY(CNT)
  MATPARSE LISTARRAY FROM LIST,@AM
  MATBUILD FIRSTHALF FROM LISTARRAY,1,MID
  CALL CHECK.LIST(FIRSTHALF)
  MATBUILD SECONDHALF FROM LISTARRAY,MID+1,CNT
  CALL CHECK.LIST(SECONDHALF)

  * -- put the lists back together
  LIST = FIRSTHALF
  LIST<-1> = SECONDHALF

END ELSE

  * -- perform the filter here
  FOR I = CNT TO 1 STEP -1
    IF LIST<I>/2 = INT(LIST<I>/2) THEN
      LIST = DELETE(LIST,I)
    END
  NEXT I                             

END

RETURN











-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Wjhonson
Sent: Wednesday, July 11, 2012 5:10 PM
To: u2-users@listserver.u2ug.org
Subject: [U2] trimming a list (a test of your ability)


1295          FOR DISPLAY.LOOP = 1 TO KEY.COUNT
1296             UTILITY.ID = KEY.LIST<1,DISPLAY.LOOP>
1297             GOSUB GET.UTILITY.RECORD
1298             IF INDEX(UTILITY.NAME,LAST.NAME,1) = 0 THEN
1299                KEY.LIST = DELETE(KEY.LIST,1,DISPLAY.LOOP,0)
1300                DISPLAY.LOOP -= 1
1301                KEY.COUNT -= 1
1302             END
1303          NEXT DISPLAY.LOOP


Comments?


_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to