Post Reply 
Programming puzzles: processing lists!
04-24-2017, 07:39 PM
Post: #25
RE: Programming puzzles: processing lists!
(04-22-2017 03:49 PM)pier4r Wrote:  Challenge 4 finished and got a strange result...

This code runs for an average of 0.86 secs for 100 lists of 100 elements.
The code of DavidM takes 0.98 secs for the same workload.

I wonder why, his code seems way more compact (although more cryptic ), doing mostly the same of what my code does, or even less.

We are essentially doing similar things here, but there's an important difference in the algorithms that makes yours faster. Notice what happens when there's no carry for a given iteration of the list subprogram: your code (nicely) just leaves the list element alone and proceeds. This results in a measurable savings of time for the overall process.

It would be interesting to see the results if you change the test input to mostly 1s for each list test. I believe that would bring more parity to the timings between our samples.

This underscores an important list processing concept: anything that can be done to minimize the list subprogram for DOLIST/DOSUBS could have a large impact on performance as list sizes increase.

And, yes, I (intentionally) did something a bit strange/cryptic with #5 that may not be very obvious. I was curious as to whether anyone would notice. Smile

Finally, a suggestion for your consideration: there's no need for you to store the 'value' variable for #4. Your subprogram is fine as-is without it:

1) remove "'value' STO"
2) remove "value" before 0 ==
3) remove "ELSE value"

Your code will be even faster!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - DavidM - 04-24-2017 07:39 PM



User(s) browsing this thread: 1 Guest(s)