Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
04-01-2014, 08:32 AM
Post: #78
RE: Programming Exercise (HP-15C, 15C LE - and others)
(04-01-2014 06:50 AM)HP67 Wrote:  If I understood what you did your User RPL version only uses the stack but your Sys Rpl version uses local variables pretty heavily. I would bet the Sys Rpl version could be tweaked to run a lot faster from the stack.

You might be surprised. Smile

My first attempt at creating the SysRPL version was entirely stack based:
Code:
    SysTime    
    %%0
    %% 10000
    
    DUP %%2 %%/>% COERCE
    #1+_ONE_DO (DO)
        DUPDUP %%1 %%- %%* %%1/ ROT %%+
        SWAP %%2 %%-
    LOOP
    
    DROP %%>%
    
    SysTime ROT bit- HXS>% % 8192 %/

It was very close to the same speed as the local vars version, but very slightly slower. I'm talking about hundredths of a second when averaged over 5 runs. If I ran them both 20 times, I'm not sure which one would have come out ahead. In the end, the local vars version was easier to read (and follow), so I posted that one.

This may not seem intuitive to some, but the use of null-named locals (as I used in the first SysRPL example I posted) as opposed to named locals (which is what you get with standard UserRPL) is significant. Null-named locals are very efficient; they are accessed via an index into a table instead of being searched out by matching a string. This means that recalling/storing null-named variables is very fast. If you can avoid some stack manipulation steps by using null-named local variables, you're likely to see a time savings as a result. Additionally, your code will be much easier to understand and maintain when you can use locals as opposed to manipulating everything on the stack.

In this case, it's nearly even in terms of time. Both versions are fairly easy to understand. In larger projects, it becomes a no-brainer IMHO. When it's close in performance, code clarity (and thus maintainability) wins.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Exercise (HP-15C, 15C LE - and others) - DavidM - 04-01-2014 08:32 AM



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