Loops of addition


A loop of addition is inherent in a FOR-NEXT loop. A FOR-NEXT loop typically provides a substantial increase in the accumulated count relative to that provided by an A = A + 1 function in a GOTO loop. Some examples:

TI CC-40:

Count: 12,110 where the previously reported count for a GTO loop was 9,339

Code: 10 FOR I = 1 TO 99999 20 NEXT I

Sharp EL-5500III:

Count: 9,140 where the previously reported count for a GOTO loop was 2,056 where I was surprised by the 4.5 fold increase.

Code: 10 FOR I = 1 TO 9999 : 20 NEXT I

Substantial increases in the count are also realized with the TI graphic machines using the code :For(I,1,99999) :End

TI-80: Count: 3,080

TI-83+: Count: 19,020

TI-85: Count: 15,490

TI-86: Count: 12,690



Palmer, I suspect Gene did not take that approach because all programmable calculators do not have looping instructions like FOR/NEXT or ISG/DSZ DSE, etc. He wanted some simple method of doing addition that could be used to compare lots of calculators. For example, the 12c has no looping instructions, but you can still loop manually.

My experience with the 33s, which does have looping instructions, is that using the looping instructions takes significantly longer than just controlling the loop manually. I did some benchmarks years ago and determined that.



The introduction to Gene's Article 1002 states in part:

... Alternative methods that count one at a time are allowed and included, such as going through an ISG/DSE loop. ...

For an example, see the entry for HP30b with TSTSYS ON.

I agree with you that the methods which use looping instructions other than a simple GOTO tend to be slower. The FOR/NEXT loop seems to be the exception.

My recollection is that Maurice Swinnen did some of this back when the TI-88 came out as a way to show that it was faster than the TI-59, but I have't been able to find the material.


Edited: 16 June 2010, 10:51 p.m.


I've found some speed comparisons of the TI-88 vs. TI-59 here: http://www.ti59.com/V7N9.pdf

Thanks to Viktor Toth, the TI-88 is also present in the n-queens benchmark.


OOPS! The numbers reported herein are with the machines operating in the APPROXIMATE mode. When the mode is changed to EXACT the count for the TI-89 for the Lbla ... Goto a changes from 6,790 to 8.860 which is substantially closer to the previously published value. Furthermore, the For ... EndFor loop increases the count instead of decreasing it as with the APPROXIMATE mode. So, I'll have to generate a new set of data for the EXACT mode and (maybe) generate a new set of data for the AUTO mode as well.


My experience with the 33s, which does have looping instructions, is that using the looping instructions takes significantly longer than just controlling the loop manually.

I did some work with my TI-89 which is in agreement with your idea that use of looping instructions takes longer. First, I did a :Lbl a :b + 1 > b :Goto a : EndPrgm loop and got 6,790 counts which is subtantially lower than the previously published value of 9,339. I could not make the Ans + 1 method work. A For...EndFor loop gave a reduced count of 4,685 per minute. That is consistent with your comment but is not consistent with results from other TI graphic machines. A Loop...EndLoop lop gave an increased count of 7,266 counts per minute. The details are:

TI-89 Platinum: Count: 6,790: Code :Prgm :Lbl a :b + 1 > b :Goto a :EndPrgm

TI-89 Platinum: Count: 4,685: Code :Prgm : For a,1,99999 :EndFor :EndPrgm

TI-89 Platinum: Count: 7,266: Code :Prgm :Loop :a + 1 a :EndLoop :EndPrgm

I did the same tests on my TI Voyage 200 with similar results but with with counts about 3 to 4 percent higher:

TI Voyage 200: Count: 7,000: Code :Prgm :Lbl a :b + 1 > b :Goto a :EndPrgm

TI Voyage 200: Count: 4,860: Code :Prgm : For a,1,99999 :EndFor :EndPrgm

TI Voyage 200: Count: 7,546: Code :Prgm :Loop :a + 1 a :EndLoop :EndPrgm


Edited: 18 June 2010, 11:52 p.m.


Palmer, it is interesting that using the looping instructions sometimes takes longer than just controlling the loop index yourself on some machines; I put a yellow post-it note in my 33s manual years ago to NEVER use ISG/DSE. But it really does depend upon the individual machine. I did a benchmark on the new 30b, and on that machine it is much faster to use the looping instructions than to do it manually.

I guess it depends upon how efficiently these instructions were implemented by the OS programmer. Obviously, Tim and Cyrille did a good job on the 30b. But Katie pointed out another area in which the 30b is not nearly as efficient as, for example, the 42s and others. I believe she said that the 42s caches the physical address of each label (object of a Goto or Call), so subsequent executions do not have to search for the location to goto. The 30b does not do this, and some programs take much longer to run because of this. We created an optimized version of the prime factor program in which the most commonly used labels are located at the beginning of memory, and did some benchmarks comparing this version with the non-optimized version, and the results were striking. Let's hope that, if the 30b ROM is ever updated, this is fixed. Of course, one could argue that the 30b is not primarily a programming machine...




I put a yellow post-it note in my 33s manual years ago to NEVER use ISG/DSE.

I admit that the ISG and DSE functions are not "speedy" when it comes to counting. But, that is not all that they do, and more importantly, they do what they do without messing with the stack.



True, but I value speed over stack (and number of instructions, usually). And, in almost every loop I've ever done, I want the loop index in X when I begin the loop during each iteration, so to loop from 1 to 30, for example, at the end of the loop I would do this on the 33s:

STO + 1

In the benchmarks I did on the 33s, this code runs faster than ISG 1.

On the 30b, there is no X<=Y, there is ?<= (which is really Y<=X), which would require a GF 1, or ?> (which is really Y>X) with GT 1, to maintain the desired loop index in X. The ISG on the 30b is much more efficient than the ISG on the 33s, however.

Possibly Related Threads...
Thread Author Replies Views Last Post
  Loops in Prime Geoff Quickfall 4 1,153 10-02-2013, 10:45 AM
Last Post: Geoff Quickfall
  Why does PEMDAS do multiplication and division before addition and subtraction? Don Shepherd 12 2,217 07-31-2013, 10:59 AM
Last Post: robert rozee
  39gii Tutorial: FOR loops is posted Eddie W. Shore 0 712 03-16-2013, 12:13 PM
Last Post: Eddie W. Shore
  New addition to my collection: 200 LX wildpig 20 4,589 08-31-2012, 06:39 AM
Last Post: Keith Midson
  HP-15C LE (Limted Edition) Bug Reports Addition Dirk E. 0 643 08-02-2012, 05:49 PM
Last Post: Dirk E.
  Using loops and SOLVE together Matt Agajanian 5 1,287 03-25-2012, 09:02 PM
Last Post: bill platt
  A great addition to the museum & DVD Matt Agajanian 0 670 03-11-2012, 06:40 PM
Last Post: Matt Agajanian
  Loops of Addition benchmark for the 41CL Monte Dalrymple 8 1,389 08-19-2010, 09:48 PM
Last Post: Wlodek Mier-Jedrzejowicz
  New addition speed test (updated with results as of 20100602 1pm CDT) ...add machines / methods --- new champion Casio F Gene Wright 47 6,725 06-13-2010, 11:50 PM
Last Post: Paul Dale
  Brute force addition speed test - various models - results? Gene Wright 39 5,889 06-03-2010, 09:15 AM
Last Post: Maarten Ambaum (Reading, UK)

Forum Jump: