Programming puzzles: processing lists!
|
11-04-2017, 02:35 PM
Post: #224
|
|||
|
|||
RE: Programming puzzles: processing lists!
(11-04-2017 07:56 AM)pier4r Wrote: Interesting, so assuming that the iteration costs in a similar way, the difference was in the function to execute. Definitely. SEQ takes the arguments you give it and constructs a User RPL program out of them. That program is then executed, and anything placed on the stack more recently than the original arguments are imploded into a list. In the case of your original SEQ invocation, this is the program that SEQ creates: Code: « This is the RPL program created by the simplified version: Code: « So you can see there's much less going on in the innermost loop in the second version, which accounts for the difference. The overhead of the FOR loop structure is roughly the same in both cases. This also gives a clue for a somewhat faster version, though there's more to type so I didn't go that direction earlier. Looking at the output of the second version, you can see that there's no need to actually EVAL a single quoted local variable -- it's simpler to place the ID in the inner loop without the quotes. Since we're using constants for all the arguments here, we already know how many elements will be in the final list. That makes it easy to use the following to create the same list result: Code: « Execution time: 4.9s I know you didn't want to use any non-native commands for this, but I can't help myself. This is actually a really good example of a situation where LSEQR comes in handy, and the fact that the step value is 0.1 makes this even easier: Code: « Execution time: 4.1s, most of which is spent doing that final division. Building the initial list of integers only takes 0.31s. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)