www.jupiter-ace.co.uk
Previous Page > General Forth Index > PCW Forth Benchmarks..
Personal Computer World January 1983 page 122
FORTH BENCHMARKS
PCW already has a set of Benchmark programs for the Basic and Pascal languages.
As Forth is becoming more widespread on personal computers Dick Pountain has produced an
equivalent Benchmark set, the first results of which are printed here.

It seems likely that during 1983 Forth will finally emerge from the shadows and take its place as a major microcomputer language. The evidence for this assertion is not hard to find: during 1982 Forth systems at reasonable prices have become available for most of the popular low priced micros, while the Jupiter Ace, reviewed in this issue, makes the language available to beginners for less than the price of many software systems. The number of professional level Forth systems under CP/M is now quite bewildering. At the West Coast Faire last year there were more Forth than Pascal products on display. IBM has commissioned and sold Forth developed software for its PC while Atari's arcade games are now developed in a graphics Forth.
This is not the place to go into how Forth works (see PCW Dec 1981 or Brodie's magnificent book Starting Forth). Nor am I going to oversell Forth as the universal panacea for programming problems as has, unfortunately, been done so often before.
After a year of working in Forth I have formed a somewhat more realistic opinion of its capabilities and shortcomings; suffice it to say that I remain impressed enough to use it whenever appropriate for serious programming tasks and to offer these Benchmarks for evaluating Forth systems.
Forth is definitely not a suitable replacement for Basic as a beginner's language, anymore than an AC Cobra is a suitable car for learner drivers. Logo is a much better bet to take on this role. What Forth does offer, as a second language, is a complete programming environment which offers more control over the computer than any other interactive system which is currently available. Notice the word interactive: the main rival to Forth for flexibility and power in systems programming is C (and its progenitor BCPL). C offers advantages over Forth in that it produces stand-alone machine code modules which can be linked to programs produced by other compilers, whereas Forth generally requires run time support from a Forth interpreter. C-produced code will usually run slightly faster, too. But C is not interactive; it is a compiler in the old Fortran tradition (and even slower to compile) and thus goes against the grain of the microcomputer philosophy. For large projects by professional programmers this doesn't matter, but for we mortals the interactive 'suck-it-and-see' approach is what makes programming bearable.
Forth is not only interactive; it is more interactive than any other language in existence. How else can you sit at a terminal and work in any number base you desire at a keystroke, dump blocks of memory, mix Assembler in with your high level code, manipulate any object from a bit up to an array or file without ever leaving the system? And it's structured, too. One myth which circulates about Forth is that the code is always unreadable; the truth is that it can be as readable as you want to make it. The commenting facilities in Forth are unlimited and since you decide word names (up to 31 characters on my system) it is your responsibility to make them intelligible. One day soon I intend to publish in PCW a fairly heavyweight piece of Forth code I have produced which is certainly as readable as Pascal.
Anyway, on to the Benchmarks. Since Forth is an extensible language it presents some problems in choosing the level at which to write Benchmark programs. In order to produce programs which stand a chance of running on all systems it is necessary to restrict the functions tested to the 'core' words which are mainly control constructs or stack manipulation words. I have not tested any lower, byte level, words as these tend to be almost 'naked' machine instructions and one ends up Benchmarking the processor not the implementation. Similarly high level structures like strings and arrays are excluded because they are not implemented on many systems. Floating point extensions are becoming more widespread and could be a candidate for future addition.
Even having decided to stick to core words there were problems over standards. There are two major variants of the Forth core, the Forth Inc version and the Forth 79 Standard plus lots of 'eccentric' versions such as Transforth and Stackworks Forth. The differences are usually only a matter of names; there are equivalent words in most systems but they may be called by different names. I  have  chosen (with one exception)  to  go  for
Forth 79 Standard words in these programs as this gives compatibility with most fig-Forth systems. The fact that my own system is 79 Standard of course didn't influence me at all.
The exception I mentioned is the word SP! which removes all the contents of the data stack. This isn't required in the standard though it is in fact implemented in a lot of 79 systems. The reason it's required is as follows. PCW's other Benchmarks, the Basic and Pascal, are analytical in the sense that by subtracting the timings of successive tests one can isolate the time due to a given instruction (not completely true for the arithmetic functions). We feel that this is a desirable feature which is why we haven't adopted catch-all tests such as Eratosthenes Sieve. (For a full account of Benchmarks see PCW Nov.)
Forth is so fast that most of the programs test 100,000 iterations (and that is barely sufficient for 'magnifier'). No Forth system in the world can hold 100,000 items on its stack and so the stack has to be cleared if we are to get a direct timing for any word which leaves a result on the stack. Hence SP! is required. I have deliberately placed it in 'magnifier' which is meant to be subtracted from the other timings as a constant overhead (thanks to Chris Sadler's Pascal BMs for the idea). If you want to run the BMs on your system and don't have SP! or an equivalent, you must write one; it hardly matters whether it's in machine code or high-level as it's part of the overhead. I had to write SP! for two of the systems timed here, PicoFORTH and GraFORTH. PicoFORTH keeps the stack pointer in a processor register; the definition in 8080 code is:-
CODE (SP!) H POP SPHL NEXT JMP
: SP! SO @ 2  (SP!) ;
The word S0, which is present in most systems is a variable holding the address of the stack base; many systems also have SP@ which fetches the address of the stack top.
GraFORTH uses RAM locations and has the unForthlike PEEK and POKE so
: SP! 7680 156 POKEW ;
Block 8001
0 ( PCW Forth Benchmarks - Dick Pountain 10th Nov 1982)
1
2  FORTH DEFINITIONS DECIMAL
3
4 : magnifier ." S" 10001 1 DO
5SP! LOOP ." E" ;
6
7 : do-loop ." S" 10001 1 DO
811 1 DO LOOP
9SP! LOOP ." E" ;
10
11 : literal ." S" 10001 1 DO
1211 1 DO 9 LOOP
13SP! LOOP ." E";
14 -->
15


Block 8002
0 ( Benchmarks 2)
1
2 VARIABLE V
3
4 : variable ." S" 10001 1 DO
511 1 DO V LOOP
6SP! LOOP ." E" ;
7
8 : literal-store ." S" 10001 1 DO
911 1 DO 9 V ! LOOP
10SP! LOOP ." E" ;
11
12 : variable-fetch ." S" 10001 1 DO
1311 1 DO V @ LOOP
14SP! LOOP ." E" ;
15 -->

Personal Computer World January 1983 page 124
FORTH BENCHMARKS

does the trick here. Some readers may wonder why TEST> and TEST< are both included. When I was checking out different candidates I discovered that on my system (xForth 1.2) a > test is 50% slower than a < test, because it is defined at high level using G. I thought this was useful knowledge as by choosing appropriate logic it is possible to save time, and so included both in the BMs.
I deliberately haven't included any timings for compilation as this is so I/O dependent; there would be no basis for comparison between disk and cassette based systems for example.
What of the systems timed here? Z-80 FORTH is a product of Laboratory Microsystems in Los Angeles and has established itself as one of the best CP/M systems available. It is based on fig-FORTH 1.1 recoded for the Z80. It features a first class screen editor, floating point extensions, and a true Z80 assembler and it has the ability to generate a new system for any RAM size of host with any required extensions included. All the high level source code is included and it uses a CP/M-compatible file format to store screens.
xForth is a British product from AIM Research of Cambridge, and also runs under CP/M. It has a 79 Standard kernel with lots of very advanced extensions. In particular, it has facilities for modular programming with local variables, run-time conditionals and conditional assembly (8080 assembler), and full CP/M file handling capabilities which can access, for instance, Wordstar files. Floating point and sequential files (with pipes and spooling) are available as extras. It has an even better screen editor than Z-80 FORTH which includes a global search-and-replace and user configurable control codes.
PicoFORTH is a 'kosher' product from Forth Inc, itself, distributed in the UK by Computer Solutions of Chertsey. Meant as an introduction to Forth programming rather than as a professional system, it is a smallish single-user subset of their multitasking polyFORTH. An 8080 assembler is provided but only the original Forth line editor which is rather spartan compared to the editors on the other systems tested. Although it boots from CP/M it does not use CP/M compatible files but 'pure' Forth blocks. This means you cannot, for instance, copy files with PIP nor interface with CP/M via system calls.
GraFORTH is a special graphics language, based on Forth, for the Apple II; it is written by Paul Lutus of Applewriter fame (notoriety?). It provides some very nice features for animated 3D graphics and music synthesizing. The demo programs impressed everyone who saw them, even given the limited resolution of Apple graphics. It is possible to draw a wire-frame picture using turtle graphics and then animate it by scaling, rotation and translation without any more drawing at all. As a Forth system it is rather eccentric with numerous wilful deviations from Forth practice which make it hard to come to or go from this to a 'standard' system. For instance, variables are handled in a Basic-like assignment statement eg, L 1 + > L and put their value rather than address on the stack when called (which is why I have no timing for 'variable'). The editor is based on the Apple Basic editor using the same ESC codes and line numbers; it is quite nice to use. No floating point or assembler is included. Unusually GraFORTH is directly threaded - ie, it compiles 6502 code rather than pointers into its headers; the effect on the time for 'dictionary-search' is very noticeable.
Working Forth is a teaching system from Mountain View Press of California based on standard fig-FORTH. Like picoFORTH, this is a 'pure' system which doesn't use CP/M files. It has a large number of screens of teaching-machine type instruction which have the nice feature that the student can come out into Forth and do exercises and then easily start at the point he/she left off (or indeed repeat a lesson). The quality of the teaching is high, if perhaps rather forbidding the total novice; it would be better to know Basic and best to know some Assembler before approaching it. It represents terrific value for money, though, because you get a full Forth system with assembler and editor (an enhanced line editor) which will keep you happy long after you finish the teaching course. They even give you the assembler source for the kernel on disk. The documentation is very rudimentary, however, as most of it is meant to be on the screen.
At the last minute before hitting the press I received a copy of Kuma Computers' Forth for the Sirius 1. This is a fig-1.1 based system written in genuine 8088 code, and as you will see from the timings it is indeed quicker than a 4MHz Z80 version except in
the odd case of 'increment' (maybe in high-level?). It seems, at cursory acquaintance, to be a nice implementation, with a simple but effective screen editor. It seems, at cursory acquaintance, to be a nice implementation, with a simple but effective screen editor. It goes well beyond the 79 Standard with a large part of the Reference Word-set included. It comes with

Block 8003
0 ( Benchmarks 3)
1
2 9 CONSTANT K
3
4 : constant ." S" 10001 1 DO
511 1 DO K LOOP
6SP! LOOP ." E" ;
7
8 : dup            ." S" 10001 1 DO
911 1 DO 9 DUP LOOP
10SP! LOOP ." E" ;
11
12 : increment   ." S" 10001 1 DO
1311 1 DO 9 1+ LOOP
14SP! LOOP ." E" ;
15 -->

Block 8004
0 ( Benchmarks 4)
1
2 : test> ." S" 10001 1 DO
3 11 1 DO 9 9 > LOOP
4 SP! LOOP ." E" ;
5
6
7 : test< ." S" 10001 1 DO
8 11 1 DO 9 9 < LOOP
9 SP! LOOP ." E" ;
10
11
12 : arithmetic    ." S" 10001 1 DO
139 2 / 3 * 4 + 5 -
14SP! LOOP ." E" ;
15 -->

Block 8005
0 ( Benchmarks 5)
1
2
3 : while-loop ." S" 10001 1 DO
4 1 BEGIN 1+ DUP 11 < WHILE REPEAT
5 SP! LOOP ." E" ;
6
7
8
9 : until-loop ." S" 10001 1 DO
10 20 BEGIN 1- DUP 11 < UNTIL
11 SP! LOOP ." E" ;
12
13
14
15 -->

Block 8006
0 ( Benchmarks 6)
1
2 : ten ;
3 : nine ten ;
4 : eight nine ;
5 : seven eight ;
6 : six seven ;
7 : five six ;
8 : four five ;
9 : three four ;
10 : two three ;
11 : one two ;
12
13 : dictionary-search ." S" 10001 1 DO
14 one
15 SP! LOOP ." E" ; -->

Personal Computer World January 1983 page 126
System
 
Z-80 FORTH
v 1.14
xForth
v 1.2
Working Forth
v 2.5
picoFORTH
 
GraFORTH
 
Kuma Forth
 
Host machine
 
Transam Tuscan
4Mhz Z80
Sharp MZ80B
4Mhz Z80 v 1.2
Transam Tuscan
4Mhz Z80
Superbrian
4Mhz Z80
Apple II Euro+
1Mhz 6502
Sirus 1
5Mhz 8088
Operating System
CP/M 2.2
 
CP/M 2.2
 
CP/M 2.2
 
CP/M 2.2
 
DOS 3.3
 
CP/M 86
 
magnifier
1.3
1.2
1.4
3.6
4.3
1.0
do-loop
9.5
8.6
10.1
11.4
18.0
6.5
literal
13.5
11.4
13.7
14.7
26.5
8.9
literal-store
19.4
16.4
20.1
21.0
27.9
13.7
variable
12.2
10.6
12.9
14.1
N/A
8.7
variable-fetch
15.8
13.6
16.5
17.7
26.8
11.5
constant
13.0
11.2
13.7
14.9
N/A
9.1
dup
16.4
14.0
17.0
18.4
30.7
11.5
increment
16.2
13.8
16.9
17.8
41.4
19.5
test>
21.4
28.0
36.2
22.9
52.1
23.3
test<
21.4
18.3
23.8
22.7
51.7
15.3
while-loop
22.45
18.9
25.4
24.2
56.2
25.9
until-loop
20.4
16.8
22.9
21.7
54.7
18.9
dict-search
10.0
8.0
10.3
12.1
5.3
6.3
arithmetic
29.1
21.0
41.3
26.0
25.7
23.5

FORTH BENCHMARKS
floating point but no assembler, and does not have full CP/M86 file compatibility though you can read a CP/M86 file into RAM at a chosen address using a routine called READFILE. It has a reasonable manual and user guide which is short on low-level information, however.
What is my overall impression of the products? As far as speed is concerned the Z80 systems were not far apart as you can see from the table. The 6502 system was slower overall than I would have expected. My money is already on the table as I am an xForth licence holder (and extremely happy with it). Z-80 FORTH runs it pretty close and is now on sale in this country, I believe. The ability to work on CP/M files from either of these is of inestimable value to me; I can write utilities such as word count programs to work on Wordstar or Cardbox files without having to buy a CP/M Basic or resort to assembler. These two also have excellent documentation which allows you to probe as deep as you will into the system.
I hope that any Forth using readers will run the Benchmarks and send in their timings so that I can print updates on an annual basis as Chris does with the Pascal. Please specify what processor and clock-rate if you do this. Any suggestions for improvements or modifications will also be welcome.
Addresses of suppliers
AIM Research, 20 Montague Road, Cambridge xForth.
Laboratory Microsystems, 4147 Beethoven St., Los Angeles, CA. 90066 Z-80 FORTH.
Mountain View Press Inc., PO Box 4656, Mountain View, CA 94040 Working Forth.
Computer Solutions Ltd, Treway House, Hanworth Lane, Chertsey, Surrey picoFORTH.
Insoft, 10175 Barbur Blvd, Suite 202B, Portland, Oregon, OR 97219 GraFORTH.
Kuma Computer Ltd.. 11 York Road, Maidenhead, Berks Kuma FORTH.
cartoon
PCW 8301 coverpage    PCW 8301  page 122

PCW 8301  page 124   PCW 8301 page 126