The term “benchmarking” refers to the process of running a computer program on a computer and comparing the time needed to complete the program against other machines. Compilers and interpreters are also benchmarked against others in order to develop the fastest applications.
One program I often use as a benchmark is the “Magic Numbers” program. The term “magic numbers” refers to those four digit numbers that fit the following algorithm:
Take the first two digits as number1, the second two digits as number2.
Add number1 to number2 giving number3.
Square number3.
If number3 is equal to the original number then the number is “magic.”
Take the number 2025 as an example. Number1 would be 20, and number2 would be 25. Number3 would be 20 + 25 or 45. Multiplying 45 by 45 gives 2025, so the number is “magic.”
Since the range of four digit numbers extends from 1000 to 9999 inclusive, there are 9000 different numbers to check. If a person could check four numbers a minute on a calculator, the job would take 2251 minutes or about 37 1/2 hours to complete! Obviously this is a good job for a computer. By using a purely mathematical algorithm, the program lends itself to any computer language. A mathematical approach also gives the solution the qualities of a good benchmark program.
The solution steps used, expressed in ZX81 Sinclair BASIC are as follows:
10 FOR X = 1000 TO 9999
20 LET A = INT(X/100)
30 LET B = X - (A*100)
40 LET C = B + A
50 IF (C*C) = X THEN PRINT X
60 NEXT X
70 STOP
In the above program line 20 gives the first two digit number, line 30 gives the second two digit number, line 40 combines them into a single number, line 50 squares the number and checks to see if it is “magic.”
When this program runs in slow mode on the ZX81 the computer takes 23 minutes 26 seconds to find the series of “magic numbers.” In fast mode the computer takes 3 minutes 44 seconds to find the series.
Luckily BASIC is not the only language available for the ZX81. Some alternative programming languages that I own are Artic’s ZX-FORTH, Semper Software’s Partial Pascal, and Intercomputer’s MCODER.
Since FORTH is one of my favorite programming languages, and one I find to be well suited for 8-bit micro processors, I tested it first. In the past I have found FORTH to be extremely fast in execution. Because FORTH is a unique language FORTH programs are often unreadable by anyone who is not familiar with the language. For those of you who are familiar with FORTH, or for those who are simply curious, I include the FORTH code:
: MAGICNO 10000 1000 DO
I DUP 100 /MOD + DUP *
= IF I . THEN LOOP ;
As I expected, FORTH showed a substantial speed increase over BASIC. In slow mode FORTH took 1 minute 17 seconds (22 minutes and 9 seconds faster than BASIC). In fast mode FORTH completed the problem in just over 12 seconds; in both cases FORTH was about 19 times faster than BASIC!
Next I tested a PASCAL compiler/editor that Semper Software developed for the ZX81 in 1983. Although not a full UCSD PASCAL, Semper did an excellent job of putting a useful Pascal in a 16K environment. Partial Pascal makes excellent use of the ZX81 system and performed the “magic numbers” program very well. The code used was:
Program Magicno (input,output);
Var origno:integer;
step1 :integer;
step2 :integer;
step3 :integer;
step4 :integer;
Begin
For origno:= 1000
to 9999 Do
begin
step1:=origno
div 100;
step2:=origno
mod 100;
step3:=
step1+step2;
step4:=
step3*step3;
if step4 =
origno then
write(origno);
end;
End.
Partial Pascal completed the program in 2 minutes 40 seconds in slow mode and 25 seconds in fast mode. In both cases Partial Pascal was about 9 times faster than BASIC.
The final benchmark was done using Intercomputer’s MCODER program to convert the Sinclair BASIC program into machine language. I would have expected a machine language program to execute the algorithm faster than any of the other languages and I was not disappointed. The MCODER version of the program ran in 1 minute 13 seconds in slow mode, and 12 seconds in fast mode.
This represents a speed increase of about 20 times over BASIC.
After completing the language tests, I decided to benchmark the ZX81 itself against other machines. I chose another well known 8-bit machine (the Apple II+), and a 16-bit machine (the IBM PS/2 running at 12 megahertz). The following table shows the results of these tests in seconds (ZX81 times are in fast mode):
ZX II+ PS/2 Forth 12+ NA 5 Pascal 25 92 1.9 MCODER 12 NA NA
As you can see the ZX81 compared very favorably to the Apple II+ system which sold in 1982 for over 20 times what the ZX81 cost. Although I am very fond of my Apple, if I want speed it appears my ZX81 is the best choice! The IBM was about 12 times faster than the ZX81, but considering that the system is 16 bit and costs about $3600 the ZX81 still comes out looking pretty good.
TSers, let ’em eat our dust!