User Tools

Site Tools


sd:star_forth_test_suite

This is an old revision of the document!


Star Forth Test Suite

Current version: 1.0

Version Pass/Fail Test Expected Results
1.0
260313
PASS signed >
-3 0 > .
0
1.0
260313
PASS : ;
: TEST 42 . ;
42
1.0
260313
PASS IF/THEN
: SIGN DUP 0 > IF 43 EMIT THEN . ;
5 SIGN
-3 SIGN
0 SIGN
+5
-3
0
1.0
260313
PASS DO/LOOP/I
: TENS 10 0 DO I . LOOP ;
TENS
0 1 2 3 4 5 6 7 8 9
1.0
260313
PASS BEGIN/UNTIL
: COUNT3 3 BEGIN DUP . 1 - DUP 0 = UNTIL DROP ;
COUNT3
3 2 1
1.0
260313
PASS BEGIN/WHILE
: COUNTDOWN BEGIN DUP WHILE DUP . 1 - REPEAT DROP ;
5 COUNTDOWN
0 COUNTDOWN
5 4 3 2 1
0
1.0
260313
PASS HERE . $030800
1.0
260313
PASS HEX $030800 @ . 0
1.0
260313
PASS $030800 C@ . 0
1.0
260313
PASS 42 HERE ! HERE @ . 42
1.0
260313
PASS : GREET .“ Hello, World!” CR ;
GREET
Hello, world!
1.0
260313
PASS : FIZZBUZZ 21 1 DO I 15 MOD 0 = IF .“ FizzBuzz” ELSE I 3 MOD 0 = IF .“ Fizz” ELSE I 5 MOD 0 = IF .“ Buzz” ELSE I . THEN THEN THEN CR LOOP ; not shown (but it works)
1.0
260313
PASS : SIMPLE 500000 0 DO LOOP ;
SIMPLE
~6 seconds (170,000 w/s) at 4MHz
1.0
260313
PASS : BENCH 500000 0 DO I DUP * DROP LOOP ;
BENCH
22 seconds (140,000 w/s) at 4Mhz

Benchmarking

The SIMPLE and BENCH tests indicate SD/FORTH is:

  • 75x faster than Stellar BASIC (1,800 lines/sec) × ~5 ops/line ≈ 9,000 ops/sec)
  • 5x to 7x faster than a real C64 running DurexForth (~25,000 words/sec)
  • Comparable to a 4 MHz Z80 running Forth850 or an 8MHz Z80B running CamelForth.

However, this is an upper end. The following MUL and DIV heavy benchmarks operate a bit slower. Here's a summary of the followinf programs:

Benchmark Words/Sec. Notes
Bare Loop 176,000 Only dispatch overhead
Stackbench 160,000 Only stack operations
DUP * DROP 136,000 Multiply, Stack Ops
ADD only 120,000 Same as Mixed but no DIV or MUL
Mixed no DIV 100,000 Same as Mixed but no DIV
FizzBench 97,000 3x MOD, branches
Mixed +-*/ 90,000 Division, Heavy Stack

The estimate is that 70% overhead is dispatch. So with a touch of opt I think the system wants to run at 180,000 words/sec, but gets tinted down by various factors. Stack operations are cheap, then come other types of operation, then MUL, DIV and MOD are considered 'heavy'. This is not unusual, and is in fact a great sign; this is a very fast FORTH.

STACKBENCH

    : STACKBENCH ( -- )
      1 2 3
      300000 0 DO
        DUP DROP SWAP OVER DROP
      LOOP
      DROP DROP DROP ;

    STACKBENCH

FIZZBENCH

    : FIZZBENCH 0 10000 0
        DO I 15 MOD 0 = IF 1 + ELSE
            I 3 MOD 0 = IF 1 + ELSE
                I 5 MOD 0 = IF 1 + THEN
                THEN
            THEN 
        LOOP
    ;
    : FB10 10 0 DO FIZZBENCH LOOP . ." hits" CR ;
    FB10

This executes in 18.5 seconds, indicating 97,000 words/sec.

BENCH-ARITH

    : ARITH ( n -- n )
      DUP 42 +
      DUP 7 -
      DUP 3 *
      DUP 2 /
      DROP DROP DROP DROP ;

    : BENCH-ARITH ( -- )
      ." Arithmetic benchmark" CR
      100000 0 DO
        I ARITH DROP
      LOOP
      ." Done" CR ;

    BENCH-ARITH

Same without DIV:

    : ARITH3 ( n -- n )
      DUP 42 +
      DUP 7 -
      DUP 3 *
      DROP DROP DROP ;

    : BENCH3 ( -- )
      ." Add/Sub/Mul benchmark" CR
      100000 0 DO
        I ARITH3 DROP
      LOOP
      ." Done" CR ;

    BENCH3

sd/star_forth_test_suite.1773389808.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki