Math Function Execution Time

Author(s): Ron Charlton
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n9 (Volume 3, Issue 9)
Date: September 1982
Pages: 16

Some calculations take longer than others on my ZX81. I timed each math function to get an idea of which function to use when faced with alternative methods of doing the same calculation and to compare the ZX81 with other computers.

Enter in FAST mode:

   1 FOR I=1 TO 1000
2 LET T=1
3 NEXT I

This program ran in 6.1 seconds against a stopwatch. This is the basic time to execute a FOR-NEXT loop and assignment 1000 times.

I replaced the “1” in line 2 with each function in turn and retimed the program. Deducting the basic loop time gives the time to do each function 1000 times. I calculated the time in milliseconds to perform each function once.

Execution times vary widely, from 4/10000th second to one tenth second. This means some methods of calculation are better than others. For integer powers up to 50 it is faster to multiply out than use the ** function. It takes more memory to multiply to get X**50, so there is a trade off. Also it’s faster to use X*0.5 than X/2.

I tried using the loop variable I in the calculations but it didn’t seem to affect the speed. This leads me to assume that the times in the table are valid for any numbers used with the functions.

By comparison, most pocket calculators and pocket computers take about 200 milliseconds per operation. Typical minicomputers use a few microseconds per operation.

Execution Times in milliseconds–Z0X81 Math Functions

Function   Time     Function     Time
ABS 1       0.4     COS 1        40.6
SGN 1       0.6     EXP 1        41.3
INT 1       1.1     ARCTAN 1     60.9
1+1         1.2     LN 1         65.0
1*1         2.0     ARCSIN 1     69.9
1-1         2.1     ARCCOS 1     72.6
1/1         2.9     TAN 1        81.9
RND        11.9     1**1        105.4
SIN 1      39.1     SQR 1       106.4