Forth Dialects


C-FORTH

( Ahl's simple benchmark )

: ->F
  0 D>F 
;

: ITIME
   TIME&DATE 12 * + 31 * + 24 * + 60 * + 60 * + 
;

VARIABLE SEED
  0 SEED !

: FRANDOM
  SEED @ NOT IF 
    ITIME SEED !
  THEN
  SEED @ 213013 * 40643 + DUP 16 RSHIFT XOR
  DUP SEED ! 
  65535 AND ->F 65535.0 F/
;

FVARIABLE S
VARIABLE T
VARIABLE ITER

: AHL
  0 ITER !
  ITIME T !
  BEGIN
    ITIME T @ - NOT WHILE
  REPEAT
  ITIME T !
  BEGIN
    0.0 S F!
    FDEPTH 2 > IF FDROP FDROP THEN
    0.0
    0.0
    ITER @ 1 + ITER !
    101 1 DO 
      I ->F 
      11 1 DO
        FABS
        FSQRT 
        FSWAP
        FRANDOM F+
        FSWAP
      LOOP
      11 1 DO
        2.0 F**
        FSWAP 
        FRANDOM F+
        FSWAP
      LOOP
      S F@ F+ S F! 
    LOOP
    ITIME T @ - 20 < WHILE
  REPEAT
  ITIME T @ - T !
  ITER @ . ." iterations" CR
  T @ ->F ITER @ ->F F/ F. ." seconds per iteration" CR
  ." Accuracy-" 1010.0 S F@ 5.0 F/ F- F. CR
  ." Random-" 1000.0 F- FABS F. FDROP CR
;


Copyright © 2001 Eric Korpela
korpela@ssl.berkeley.edu