Post Reply 
Programming puzzles: processing lists!
05-26-2018, 02:48 PM
Post: #240
RE: Programming puzzles: processing lists!
(05-26-2018 10:17 AM)pier4r Wrote:  If instead I size a list large enough to likely keep the output I expect, therefore only modifying its elements. Is it any faster than extending a list?

Unfortunately, no. In fact, appending a single element to the end of a list is probably still faster than using PUT, since there's less work going on to determine segment sizes before copying to the new list object.

Even with PUT, an entirely new list is built by copying everything before the new element, then the new element, then everything after the new element into the new list object. If you think about the nature of RPL lists for a moment, you'll understand why this is: since the list contains the actual objects themselves (instead of pointers), a newly "PUT" object may be a different size than the previous one. Even if it is the same size, I'm pretty sure the code just uses the same copy-to-a-new-list method. You can see this simply by timing some tests.

To be fair, I have to point out that copying memory from one location to another on the ARM-based systems is helped substantially due to the inclusion of some native ARM pseudo-opcodes that were created for the Saturn emulation layer. Skipping objects (to determine sizes or simply to find the next item) and copying memory blocks are such common operations on these systems that it made sense for the designers to create ARM-native opcodes to do the heavy lifting (along with some other common functions). This is one of the reasons that it's hard to guesstimate how much faster equivalent code will run on the ARM systems compared to a native Saturn CPU -- if there's lots of skipping and copying going on, the code will likely run much faster on the ARM systems than other code that is mostly bogged down just by number crunching.

While keeping objects on the stack instead of in list form during the execution of a program or subroutine requires "stack juggling" within your code, it will almost always pay off in performance gains.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - DavidM - 05-26-2018 02:48 PM



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