Post Reply 
Basic RPL question
02-28-2016, 03:27 PM
Post: #16
RE: Basic RPL question
(02-28-2016 01:02 PM)Graan Wrote:  I was using 'set - actt' EVAL for better readability. I will have more formulas later on and thought this was a good idea.
Why is it better to put the variables on stack?

It depends on your definition of "better". Consider the following two program objects:
Code:

Test1
\<<
1. 2. \-> x y
  \<<
    'x + y' EVAL
  \>>
\>>

Test2
\<<
1. 2. \-> x y
  \<<
    x y +
  \>>
\>>

Both Test1 and Test2 provide the same results, the only difference being the syntax of how the method is implemented. Being purely objective, there are at least two specific advantages with Test2: size and speed.

Test1 occupies 50.5 bytes, Test2 weighs in at 43. So the stack-based method in Test2 saves roughly 15% of the space in this case.

That's nice, but minor in comparison to the speed improvements. On my 50g, I looped both programs a total of 300 times and the total duration of each was as follows:

Test1: 18.37 seconds
Test2: 2.12 seconds

The time savings here are substantial, and I would suggest that this is generally the case for stack-based vs. algebraic function evaluation.

So the stack-based method is measurably better regarding size and speed.

That said, I would still argue that there are advantages to the Test1 syntax in two areas which are much more subjective and therefore harder to measure:

- Readability
- Maintainability

Stack-based computations are smaller and faster, but require more care to read and maintain when you come back to them later. Are your formulas likely to change a lot during development? If yes, then using the algebraic notation might make the most sense during that process. Once you've got everything working the way you want, you could then go back and change to the stack-based syntax to gain the size and speed savings. Are those savings inconsequential in the final program? Then leaving it with embedded algebraics might make the most sense for later maintenance.

You are the only one who gets to decide what is "better" in this case, because you are the one who has to live with the results. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Basic RPL question - Graan - 02-25-2016, 03:05 PM
RE: Basic RPL question - rprosperi - 02-25-2016, 03:19 PM
RE: Basic RPL question - David Hayden - 02-25-2016, 03:36 PM
RE: Basic RPL question - wojtek - 02-25-2016, 04:25 PM
RE: Basic RPL question - Graan - 02-25-2016, 07:53 PM
RE: Basic RPL question - David Hayden - 02-25-2016, 08:32 PM
RE: Basic RPL question - wojtek - 02-25-2016, 08:48 PM
RE: Basic RPL question - Graan - 02-25-2016, 08:54 PM
RE: Basic RPL question - wojtek - 02-25-2016, 08:35 PM
RE: Basic RPL question - Graan - 02-28-2016, 09:56 AM
RE: Basic RPL question - wojtek - 02-28-2016, 10:14 AM
RE: Basic RPL question - Paul Dale - 02-28-2016, 10:13 AM
RE: Basic RPL question - Graan - 02-28-2016, 01:02 PM
RE: Basic RPL question - DavidM - 02-28-2016 03:27 PM
RE: Basic RPL question - rprosperi - 02-28-2016, 06:13 PM
RE: Basic RPL question - Graan - 02-28-2016, 07:00 PM
RE: Basic RPL question - Han - 02-28-2016, 02:26 PM
RE: Basic RPL question - Graan - 02-28-2016, 03:22 PM
RE: Basic RPL question - Graan - 02-28-2016, 05:05 PM
RE: Basic RPL question - DavidM - 02-28-2016, 06:23 PM
RE: Basic RPL question - Tugdual - 02-28-2016, 10:01 PM
RE: Basic RPL question - David Hayden - 02-28-2016, 11:28 PM
RE: Basic RPL question - DavidM - 02-29-2016, 12:30 AM
RE: Basic RPL question - wojtek - 02-29-2016, 12:39 AM
RE: Basic RPL question - Claudio L. - 02-29-2016, 03:48 AM
RE: Basic RPL question - Han - 02-29-2016, 04:19 AM
RE: Basic RPL question - DavidM - 02-29-2016, 05:22 AM



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