Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Day 024: LCASE$
#8
(12-04-2022, 05:57 PM)mnrvovrfc Wrote:
(12-04-2022, 01:48 PM)SMcNeill Wrote: More coding for the programmer, but the difference in performance is going to be very noticeable.  Here, I simply made a temp array to hold all the elements of our normal Array, and I made them all lowercase *ONCE* for comparison usage.  The first routine made calls to LCASE$ twice each loop, and repeated that same process over again a second time for the outer loop.
:
Use LCASE$ and UCASE$ when you need them; just use them wisely and judiciously -- especially if your program is running slower than you'd like and you need to improve speed and performance with it.
In some cases might have to do two swaps and leave out the second transfer of array elements, discarding the "temparray" because otherwise the letter-case of the elements of "array" is destroyed only for the sake of doing fast comparisons. Only compare elements of "temparray" but swap things in both arrays to keep them in sync.

Aye.  The way I have it would turn your original array all lowercase.  The alternative is, as you suggest:

Code: (Select All)
DIM tempArray(UBOUND(Array)) AS STRING
FOR i = 0 TO UBOUND(Array)
    tempArray(i) = LCASE$(Array(i))
NEXT

 FOR x = 0 TO UBOUND(tempArray)
    FOR y = 0 TO UBOUND(tempArray)
        IF tempArray(x) < tempArray(y) THEN SWAP tempArray(x), tempArray(y): SWAP Array(x), Array(y)
    NEXT
NEXT

If this is still slow for you (and it's not the bubble sorts fault...), then the trick would be the make an index to reference the arrays with, and then you just swap the index values while leaving the arrays intact until you exit the sort routine, and then you build the array in the order you like.  (But that's more of a lesson on data indexing/manipulation than it is on LCASE$, so we'll save going into it for another day.)  Wink
Reply


Messages In This Thread
Day 024: LCASE$ - by Pete - 12-04-2022, 05:17 AM
RE: Day 024: LCASE$ - by mnrvovrfc - 12-04-2022, 12:01 PM
RE: Day 024: LCASE$ - by luke - 12-04-2022, 01:25 PM
RE: Day 024: LCASE$ - by SMcNeill - 12-04-2022, 01:48 PM
RE: Day 024: LCASE$ - by mnrvovrfc - 12-04-2022, 05:57 PM
RE: Day 024: LCASE$ - by SMcNeill - 12-04-2022, 10:47 PM
RE: Day 024: LCASE$ - by Pete - 12-04-2022, 04:10 PM
RE: Day 024: LCASE$ - by Pete - 12-04-2022, 06:47 PM
RE: Day 024: LCASE$ - by SMcNeill - 12-04-2022, 11:16 PM
RE: Day 024: LCASE$ - by Pete - 12-05-2022, 12:59 AM
RE: Day 024: LCASE$ - by luke - 12-05-2022, 07:30 AM
RE: Day 024: LCASE$ - by mnrvovrfc - 12-05-2022, 08:24 AM
RE: Day 024: LCASE$ - by Pete - 12-05-2022, 10:38 AM



Users browsing this thread: 5 Guest(s)