Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Efficiency
#4
(08-11-2024, 01:21 AM)TerryRitchie Wrote: If those tips/tricks happen to work well with efficiencies like you point out then heck ya, I'm all for them. Your SELECT CASE use above is very ingenious and I'll start using that. I don't seem to able to think outside of the box as far as you do when it comes to clever, but still understandable, optimizations.

I think the first place where I *really* had an explosion of code added to my program, which truly made a mind-boggling ump in performance was when I was working on the QBDbase stuff back at the original forums that Galleon kept up and running for us.  I had a really simple patch of code that looked something like:

FOR x = 1 to limit
   For y = 1 to limit
         IF user_data$ = foo AND user_type = fart THEN
              ...do some stuff
         END IF
    NEXT
NEXT

Maybe 50 lines of code in total.  Nothing impressive, and it ran fine.   It just ran slow  -- (it was the sorting routines where you could sort your database by whichever field you desired, as I recall).   Incredibly slow, as in taking minutes to run with a 1,000,000+ record database.

I found that to be unacceptable, so I went back and stripped the hell out of that routine.   What I ended up with looked much more like:

IF user_data$ = foo AND user_type = fart THEN
      FOR x = 1 to limit
             FOR y = 1 to limit
                sort stuff
        .     NEXT
      NEXT
ELSEIF  user_data$ = foo AND user_type = fart2 THEN
      FOR x = 1 to limit
             FOR y = 1 to limit
                sort stuff
        .     NEXT
      NEXT
ELSEIF....
END IF

I moved that IF checking outside the FOR ...LOOPS, which required that the contents of the FOR-LOOP was basically copy/pasted inside each IF condition, which resulted in 1000 lines of code, instead of 50 -- and those routines now ran in 0.02 seconds instead of minutes!!



A change in structure that produced a TON more code, (mainly as I say, just all copy-paste code), but which ran an unbelievable speed faster!  It's where that concept that "MORE IS LESS SOMETIMES", really resonated with me.  It was like getting slapped upside the head with a week old fish -- it left an impression which has still carried with me, even to this day.

And thus, I really don't care about the line number count anymore.  Can I write code in a fraction of the lines?  Sure I can!  But it's not just about writing code in the shortest amount of code, or the fastest I can toss it out onto the screen anymore.  Now, I try to think and organize a way to separate things into the smallest repetition possible, with the fewest decisions required, when I'm needing to build something around speed or efficiency.

For example -- I used to just write word search routines to load a list of words from 1 to limit, and then search them for the word/term in question.  Now, I tend to break those down to multiple word lists, each organized by length of word.

If you're searching for things that closely match "Stve" for a name, you don't need to compare it against "onomatopoeia".  Just compare it with the word lists that are Len("Stve") - 2 TO Len("Stve") + 2 in length and look for close matches.   Now, you're not searching and checking one 250,000 word database for matches.... You're checking 5 databases that are a fraction of that size -- containing only 2 to 6 letters.



It's more coding involved, but the performance improvements are definitely worth it.  It just requires trying to so a little more thinking than just "How do I make this work"....  It involves coding around the thought, "How can I break this down to make it work, with as few checks as possible." 

Wink
Reply


Messages In This Thread
Coding Efficiency - by SMcNeill - 08-11-2024, 12:16 AM
RE: Coding Efficiency - by TerryRitchie - 08-11-2024, 01:21 AM
RE: Coding Efficiency - by SMcNeill - 08-11-2024, 03:25 AM
RE: Coding Efficiency - by CharlieJV - 08-11-2024, 01:29 AM
RE: Coding Efficiency - by Pete - 08-11-2024, 07:22 PM
RE: Coding Efficiency - by Dimster - 08-12-2024, 06:34 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 09:46 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:11 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:23 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:28 PM
RE: Coding Efficiency - by TerryRitchie - 08-14-2024, 01:21 AM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:53 PM
RE: Coding Efficiency - by Pete - 08-14-2024, 03:38 PM
RE: Coding Efficiency - by SMcNeill - 08-14-2024, 04:26 PM
RE: Coding Efficiency - by mdijkens - 08-15-2024, 11:29 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 03:20 PM
RE: Coding Efficiency - by Kernelpanic - 08-15-2024, 05:57 PM
RE: Coding Efficiency - by justsomeguy - 08-15-2024, 06:06 PM
RE: Coding Efficiency - by TerryRitchie - 08-16-2024, 03:21 AM
RE: Coding Efficiency - by justsomeguy - 08-16-2024, 07:09 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 11:14 PM
RE: Coding Efficiency - by dano - 08-16-2024, 12:33 AM
RE: Coding Efficiency - by Pete - 08-16-2024, 12:35 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 01:55 AM
RE: Coding Efficiency - by Pete - 09-11-2024, 06:45 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 07:59 AM
RE: Coding Efficiency - by bplus - 09-11-2024, 01:51 PM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 02:01 PM
RE: Coding Efficiency - by bplus - 09-11-2024, 02:39 PM
RE: Coding Efficiency - by Pete - 09-11-2024, 02:48 PM
RE: Coding Efficiency - by dano - 09-12-2024, 01:41 PM
RE: Coding Efficiency - by Jack - 09-12-2024, 04:01 PM
RE: Coding Efficiency - by Kernelpanic - 09-12-2024, 08:13 PM
RE: Coding Efficiency - by Pete - 09-13-2024, 06:56 PM



Users browsing this thread: 26 Guest(s)