All TI calculators allow to omit RETURN at the end of a program executed as a subroutine, this RETURN is implied automatically at the eng of that program. I type this code:

Code:
PROGRAM:INTEGRAL
Prompt A:Prompt B
Prompt N:2^N->M
A->G:prgmFN:P->I
(B-A)/(2*M)->D
M->O
Lbl Z
G+D->G:prgmFN:I+P*4->I
G+D->G:prgmFN:I+P*2->I
DS<(O,1)
Goto Z
B->G:prgmFN:I-P->I
I*D/3->I
Pause I
Stop

PROGRAM:FN
1/sqrt(2*pi)*e^(-G^2/2)->P
Return

It's a simple Simpson's integration algorithm ported directly from a Citizen SRP-320. I take a=-1.96, b=1.96, m=2^9 or 2^11.
And now the strangeness begins...
If I omit RETURN at the end, the calculation takes MORE time than with explicit RETURN. The difference is (at m=2^11) 13..15 seconds on a TI-86, 4 seconds on a TI-83, approx. 1 second on a TI-73 Explorer. The difference is very small, but it can be reliably measured and reproduced. Why does it happen?

PS, do other calculators (e. g. HP) have the possibility to omit RETURN? And does it affect the calculation time?
I wish I had a TI-86, that is an interesting find. If anything, I would have expected the Return to make it slower.
I'm guessing it could be a peculiarity of how the Z80 TI-BASIC parsers were coded. I'm not surprised to see the TI-86 have the largest performance difference, as it's slower at almost everything in general (it has multiple pages of RAM, and the regular bank switching the OS has to do to manage variables across those pages incurs a significant performance penalty).

I haven't gotten around to actually testing, but I would expect the results on the 68K TI calcs (TI-89, et. al.) and other brands to be completely different.

It might be interesting to run this test on the TI-81, TI-85, and TI-82, and see if the Return makes a difference there, as those were the earliest Z80 TI graphing calculators.
I didnít use the above program, but I created my own program that used an internal subroutine. I ran it one time without the return and once using the return at the end of the subroutine. On my TI 89, one run took 45 seconds and the other took 46 seconds. I used the timer function to time the runs and since the timer function has about a one second resolution, I would say that there isnít much of a difference between the two runs.
I think this is an interesting topic, so I went ahead and tried it a few times both with and without returns on some more calcs. On the TI-81, I had to use the End token which is the equivalent to the Return.
    TI-81: No significant difference ( 1:18 )
    TI-85: No significant difference ( 2:20 )
    TI-86: approximately 3 seconds difference reliably ( 2:20 with Return, 2:23 without Return )

When I say "No significant difference", I mean that all runs were within less than a second of eachother, so given that I'm measuring these with a stopwatch, we'll consider it within error. I wasn't able to replicate the 13-15 second difference you experienced, but I still found a small but not insignificant discrepancy. I'm unsure what causes this. It was suggested in IRC that it may be due to the way the TI-86 handles memory paging, but I'm not convinced yet.
I get 76 seconds on the CE using the following code with Return:
Code:
checkTmr(0->C
For(A,1,10000
prgmA
End
Disp checkTmr(C

PROGRAM:A
Return
And 75 seconds without the Return.

I get 89 seconds on the CE using the following code with Return:

Code:
PROGRAM:A
A
Return
And 92 seconds without the Return.

So I deem the difference almost neglectable in practice on the CE (I would like to mention that there is a bunch of stuff in my calculator's Archive which could have [though unlikely have] effected performance.)

Testing the second one with the CEmu timer, which I forgot is broken, I got 35 seconds with and 41 seconds without.
LogicalJoe;

When you say, 76 seconds on the CE, are you referring to the TI-84 Plus CE. The reason I ask is, I keyed your program on my TI-84 Plus CE and it took 12 seconds with or without the Return in program A. Is your For loop 1,10000, Iíve only had the TI 84 plus CE since Xmas.


PS.
I put 30 lines of just : in program A without the Return and it took 29 seconds. Adding the Return on the first line with 29 lines of : after it was 12 seconds. So the Return matters if thereís a bunch of lines after it.
I also got a small difference in TI-86 execution time in a set of programs that looks like this:

Code:
PROGRAM:TEST
:For(x,1,1000)
:TEST2
:End

PROGRAM:TEST2
:sin(x)
:Return


I timed program TEST with and without the Return at the end of TEST2. But there didn't really seem to be any measurable difference except when there was a calculation of some sort as the first line of TEST2. In that case, Return seemed to be very slightly faster, but only by a couple of percent.

Just for kicks, I ran a similar test on the HP Prime (first hardware revision):

Code:
EXPORT TEST()
BEGIN
LOCAL X,T;
T:=TICKS;
FOR X FROM 1 TO 1000000 DO
TEST2;
END;
TICKS-T;
END;

EXPORT TEST2()
BEGIN
SIN(A);
RETURN;
END;

Average run time of four trials with return was about 265 seconds, while average time without it was 262. Note that this is for 1,000,000 repetitions each, which means the difference is extremely minute.

The HP 49g+/50g calculators have a user language that enforces strict structured programming, so the only possible type of return there is the implied return at the end of a program. There is no early return unless you force it by throwing and catching errors, which I'm guessing would be slower, or write routines in the system language, which permits all sorts of funky flow-control tricks.

dave1707 wrote:
I put 30 lines of just : in program A without the Return and it took 29 seconds. Adding the Return on the first line with 29 lines of : after it was 12 seconds. So the Return matters if thereís a bunch of lines after it.

That makes sense because it takes the parser a certain amount of time to read and process even blank lines. With the Return, it can just go straight back to the calling program without caring about what follows.
Quote:
TI-86: approximately 3 seconds difference reliably ( 2:20 with Return, 2:23 without Return )

Is it m=2^9? Try at m=2^11 or 2^12.

PS, on Casio calculators (e. g. 9750Gii) RETURN makes execution slightly slower. But not on TI...
I have a question that maybe someone else can try. Does it take longer for a program to execute a subroutine if its at the beginning or end of the program list. In other words, would the time be different if the subroutine name began with an A or with a Z if there were a lot of programs. I only have 5 programs so I donít think that will make enough of a difference to time.
siealex wrote:
Is it m=2^9? Try at m=2^11 or 2^12.

For 2^11, does that mean entering just ď11Ē at the m= prompt? On my 86, I got about 20m:05s vs. 19m:56s of run time, or 5m:02s vs. 4m:59s with 2^9. In other words, adding the Return seems to make execution time roughly 1% faster.
Yes, just 11. I got 10:55..10:57 with RETURN, 11:08..11:09 without it. Maybe it's a different version of the device. What is the date code of your device?
It's August 1997, with ROM 1.4. It could also be because I did not reset the calc before running the tests and there was quite a bit of stuff loaded in RAM. This could influence the results to some degree, though I'm not sure by how much.
Travis wrote:
It's August 1997, with ROM 1.4. It could also be because I did not reset the calc before running the tests and there was quite a bit of stuff loaded in RAM. This could influence the results to some degree, though I'm not sure by how much.

Given that I was getting around 140 seconds on a freshly cleared device, it looks like it makes a significant difference. Presumably, the OS has to shuffle things around different pages a lot more when the RAM is getting full.
^ That could well be. I forgot that the OS on the TI calcs keeps RAM defragmented with every variable change, which could result in a lot of time copying blocks of memory, especially on the 86.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement