|Efficient coding practice for RPN programming|
Message #1 Posted by Les Wright on 14 Feb 2007, 12:39 a.m.
I know this is computer science 101, which I never formally studied, but I somehow recall that computers can do addition faster than multiplication.
I am working on a program for the 33S that has to double the contents of the X register on a couple of occasions, but it does it repetitively, in a loop.
I have the sense, without putting a clock to it, that using "ENTER +" makes things go perceptibly faster than "2 *". How many times the B busy indicator flashes is my quasi timer. In the former situation, it flashes twice then the answer is returned, and in the latter situation, it takes a little longer to flash three times for the same input before returning an answer.
The loop in question is performed 24 times, and I am impressed that with the naked eye I can perceive the slight time savings.
Does this all make sense? Is it generally faster to double a number by adding it to itself than multiplying it by 2? I sense yes.
p.s. on the 41 series and 42S one can ingeniously do it in one step--ST+ X. JM Baillard uses this motif inngeniously in several of his programs in the library.
Edited: 17 Feb 2007, 3:29 p.m. after one or more responses were posted