Post Reply 
RPL programming questions
02-18-2014, 11:31 PM
Post: #7
RE: RPL programming questions
(02-18-2014 07:15 PM)peacecalc Wrote:  Surprising competition,

I wrote three little programs, for testing the speed of hp 50g recalling 5000 times five different storeplaces

...

Greetings
peacecalc

A more typical use of both global and local variables in UserRPL uses the variable name without the single quotes, which implicitly "executes" the variable. In the case of numerical objects, this results in the object simply being recalled to the stack. As such, no explicit "RCL" step is required in your examples if the variables are referenced without the quotes.

When changing the code in this way, I think you'll find the execution times of TGLO and TLOC are more in line with expectations. Here's your TGLO when re-coded in this manner:

Code:

\<< 1, 'A' STO
    2, 'B' STO
    3, 'C' STO
    4, 'D' STO
    5, 'E' STO
    TICKS
    1, 5000, START
             A DROP
             B DROP
             C DROP
             D DROP
             E DROP
              NEXT
    TICKS SWAP - 8192 /
    { A B C D E } PURGE
\>>

My 50g gives times of 23 secs for TGLO2 and 21 secs for TLOC2.

IMHO, the real time savings for local variables comes when coding in SysRPL. SysRPL code can access locals in a special way that uses an offset table instead of named variables. This significantly reduces the time to locate the objects in memory. These locals have no names, and are referenced by a numerical index instead. To aid readability, SysRPL coders can take advantage of compiler DEFINEs to give meaningful names to these local variables as follows:

Code:

RPL

DEFINE   Rcl_A    1GETLAM
DEFINE   Rcl_B    2GETLAM
DEFINE   Rcl_C    3GETLAM
DEFINE   Rcl_D    4GETLAM
DEFINE   Rcl_E    5GETLAM

::
   ( no args required )
   CK0NOLASTWD

   ( Place reals 1-5 on stack, bind to LAMs )
   %1 %2 %3 %4 %5
   NULLLAM #5 NDUPN DOBIND

   ( Get current TICKS )
   SysTime

   ( Loop 5000 times: Recall each LAM and DROP )
   # 5000 #1+_ONE_DO (DO)
      Rcl_A DROP
      Rcl_B DROP
      Rcl_C DROP
      Rcl_D DROP
      Rcl_E DROP
   LOOP

   ( Get current TICKS, subtract starting time )
   SysTime SWAP bit-

   ( Divide by 8192, yielding seconds )
   HXS 4 0002 bit/

   ( release LAM bindings )
   ABND
;

SysRPL code usually provides a speed benefit, and the above is no exception. It completes on my 50g in 3 seconds.

Regards -
David
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL programming questions - HP67 - 02-17-2014, 01:54 PM
RE: RPL programming questions - peacecalc - 02-17-2014, 03:10 PM
RE: RPL programming questions - Joe Horn - 02-18-2014, 01:06 PM
RE: RPL programming questions - HP67 - 02-18-2014, 01:39 PM
RE: RPL programming questions - peacecalc - 02-18-2014, 07:15 PM
RE: RPL programming questions - DavidM - 02-18-2014 11:31 PM
RE: RPL programming questions - HP67 - 02-19-2014, 09:52 AM
RE: RPL programming questions - HP67 - 02-19-2014, 02:15 PM
RE: RPL programming questions - HP67 - 02-20-2014, 03:27 PM
RE: RPL programming questions - DavidM - 02-19-2014, 05:23 PM
RE: RPL programming questions - HP67 - 02-20-2014, 03:40 PM
RE: RPL programming questions - DavidM - 02-20-2014, 04:10 PM
RE: RPL programming questions - peacecalc - 02-19-2014, 04:15 PM
RE: RPL programming questions - HP67 - 02-20-2014, 04:36 PM
RE: RPL programming questions - RMollov - 02-24-2014, 12:47 PM



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