A question about execution speed comparisons
http://forum.6502.org/viewtopic.php?f=5&p=60986#p60969 causes me to present a table where I have noted the execution speed of various computers running a simple program. In order not to stress the original topic I moved to this place.
Code:
B A S I C - B E N C H M A R K (from BASBENCH.TAB, 28.08.93)
=============================
┌───────────────────┬──────────────────────────────╥─────────────────────┬────────────────────────────┐
│ EINGABE │ ERGEBNISSE ║ EINGABE │ ERGEBNISSE │
│A: 1000 , 20 │ 907 , 887 , 20 ║ D: 32000 , 50 │ 19661 , 19609 , 52│
│B: 2000 , 30 │ 1361 , 1327 , 34 ║ E: 32000 , 70 │ 31469 , 31397 , 72│
│C: 9999 , 35 │ 9587 , 9551 , 36 ║ F: 500000 , 100 │ 370373 , 370261 , 112│
└───────────────────┴──────────────────────────────╨─────────────────────┴────────────────────────────┘
Ausführungszeiten verschiedener Rechner/Programme (vgl. ggf. Listings, alle Zeitangaben in Sekunden) :
──────────────────────────────────────────────────────────────────────────────────────────────────────
Rechner/CPU-Typ Progr.sprache Listing A B C D E F
----------------- ---------------- ----------------- ----- ------ ------ ------ ------ ------
SYM (6502,1MHz) Basic1.1 BasBenc1 46,7 75,1 812,7 2014,0 3696,1 ____,_
CBM 3032 (-"-) Rom-Basic BasBenc1 48,0 80.0 ____,_ ____,_ ____,_ ____,_
Badge (6502, 2MHz) VTL02C ~Basic,UINT,MOD 9,6 16,3 222,8 590,0 1126,6
" EhBasic V2.22 BasBenc1 11,6 19,3 252,6 662,4 1257,3
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
APPLE II Rom-Basic BasBenc1 44,8 71,8 777,0 ____,_ ____,_ ____,_
" Woz Basic ~VTL02 22,5 38,5 526,0
Apple //e, 128KB Plasma2.0 (JIT) ~C(V2) (int) 5,72 9,3 118,36
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
Atari 800XL FastBasic_3.5 ~C(V2)(modulo) 5,3 9,0 123,3 326,1 620,4 THX 2 dsmc (post#63001)
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
C64 (6502, 1MHz) Basic BasBenc1 48,0 118,0 1412,0 3516,0 10447,0 45819,0 THX 2 Jeff_Birt
" DurexForth very close to Basic 18,0 30,0 374,0 1530,0 2352,0 see post #62871
" DurexForth -"- + sqrt2 18,0 26,0 334,0 861,0 1615,0 see post #63055
" DurexForth -"- + sqrt2 in asm 12,0 19,0 276,0 740,0 1416,0
" DurexForth ~C(V2)(modulo..) 11,0 18,0 242,0 637,0 1209,0
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
65C02 homebrew dflat Basic int, modulo 3,95 6,51 81,61 - 65C02 @ 5,36MHz; THX 2 dolomiah
65C02 pocket EhBasic 2.22p4C BasBenc1 2,78 4,68 61,92 162,51 308,33 - 65C02 @ 8Mhz; THX 2 floobydust
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
OSI 600(Superbrd.) OSI Basic V1.0 (MS) " 25,3 52,1 642,4 - 6502 @ 0.9825Mhz
Jaguar (homebrew) EhBasic V2.22 " 1,46 2,42 31,40 82,29 156,06 - W65C02 @ 16MHz
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
BBC (65C02, 4MHz) HiBASIC (IV) ~BasBenc1 5,87 9,96 137,27 363,96 694,67
" running on 2.µP +% cached SQR() 3,56 5,96 78,7 207,93 397,85
B-Em (6502, 4MHz) Assembler ~Pascal V2 0,09 0,15 2,54 7,70 17,53 856,79 ~ var.len.div., THX 2 Chromatix
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
65020 (5MHz) Assembler ~Pascal V2 0,039 0,066 0,92 2,44 4,64 140,05
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
MC68000 (4MHz) Assembler Assembler V1.0 int 0,x 0,x 3,9 9,9 18,5 ____,_
" " Assembler V1.1 int 0,x 0,x 3,0 7,6 14,1 ____,_
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
TRS-80 M 1 (Z80) Level2-Basic BasBenc1 68,7 112,1 ____,_ ____,_ ____,_ ____,_
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
ExorSet 163 Basic09 ≈ Pascal V1.0 10,5 16,5 183,8 ____,_ ____,_ ____,_
CoCo3 (0,89MHz) Disk Ext.Basic1.1 BasBenc1 60,6 97,9 1090,1
" (1.78Mhz) " " 30,4 49,0 545,1
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
EurocomII (6809) Basic V3.1 BasBenc1 18,3 30,6 403,2 ____,_ ____,_ ____,_
E II V7 (1.34MHz) Extended Basic BasBenc1 55,6 93,4 ____,_ ____,_ ____,_ ____,_
" ( TSC GBAS ) Integervariable 42,1 69,8 ____,_ ____,_ ____,_ ____,_
" OmegaSoft PASCAL s. Listing V1.0 5,2 8,2 81,2 196,8 352,0 ____,_
" Compiler V 1.10 s. Listing V2.0 3,4 5,5 67,5 173,2 323,1 ____,_
" Windrush C Comp. V2.0 (int) 2,4 4,1 51,0 131,8 245,8 ____,_
" noStkchk+optimize V2.0 (long) 10,8 18,3 249.5 654,6 1236,1 ____,_
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
Amiga 2000 (68K) AmigaBasic V BasBenc1, ShortFP 9,3 15,3 190,5 ____,_ ____,_ ____,_
" " BasBenc1, Integer 8,0 13,0 158,1 ____,_ ____,_ ____,_
" Lattice-C V3.10 C-Listing V1 ieee 6,4 11,0 152,7 401,8 784,0 ____,_
" " ffp 1,8 2,8 35,7 94,4 179,1 5740,0
" " C-Listing V2 long 0,x 0,x 6,6 16,8 31,7 1094,2
" AM-Modula-2 V3.1 Modula2-Vers. 1.0 1,2 1,8 12,5 27,0 ____,_ ____,_
" " Modula2-Vers. 1.1 1,3 1,9 13,7 30,2 52,3 1013,1
" " Modula2-Vers. 2.0 0,x 0,x 8,2 20,8 39,3 1129,2
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
PC-XT TurboPascal 3.02 Pascal V1.0 (16Bit) 2,4 3,5 25,6 51,9 ____,_ ____,_
(8088,10 MHz) " Pascal V2.0 (16Bit) 0,x 0,x 4,2 10,5 ____,_ ____,_
" TurboPascal 4.0 Pascal V1.0 (16Bit) 2,0 3,0 20,6 41,7 ____,_ ____,_
(V20 , 10 MHz) " " 1,9 2,7 19,1 38,2 65,2 ____,_
(8088, 10 MHz) " Pascal V2.0 (16Bit) 0,x 0,x 3,4 8,3 ____,_ ____,_
(V20 , 10 MHz) " " 0,x 0,x 2,1 5,0 9,1 ____,_
(8088, 10 MHz) " Pascal V2.0 (32Bit) 0,x 0,x ____,_ 68,7 ____,_ ____,_
(V20 , 10 MHz) " " 0,x 0,x 23,9 63,0 119,9 ____,_
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
(8088, 10 MHz) Turbo-C V1.5 C-Listing V1.0 5,8 9,9 137,2 ____,_ ____,_ ____,_
(V20 , 10 MHz) " " 5,0 8,6 118,7 ____,_ ____,_ ____,_
(8088, 10 MHz) " C-Listing V2.0 long 0,x 0,x 8,5 21,9 ____,_ ____,_
(V20 , 10 MHz) " " 0,x 0,x 7,0 18,0 33,8 3602,0
" " C-Listing V2.0 int 0,x 0,x 1,2 2,8 5,1 ____,_
(Inboard-PC,16MHz) " C-Listing V2.0 long 9,7 976,2
( " ) " ---"--- + 286-Option 9,4 1019,4 !!
( " ) " C V3.0 long, ohne 286 9,2 982,8
( " ) " ---"---, mit 286,wordaligned 9,3 986,8
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
(8088, 10 MHz) GW-Basic V3.22 BasBenc1, ShortFP 9,3 15,3 195,7 ____,_ ____,_ ____,_
(V20 , 10 MHz) " " 8,7 14,4 183,8 ____,_ ____,_ ____,_
(8088, 10 MHz) GW-Basic V3.22 BasBenc1, Integer 7,7 12,6 156,5 ____,_ ____,_ ____,_
(V20 , 10 MHz) " " 7,3 12,0 148,4 ____,_ ____,_ ____,_
(V20 , 10 MHz) " 40 C% mod D% = 0 ? 6,1 9,7 115,7 ____,_ ____,_ ____,_
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
80552 (11.06MHz) MI-C8051 V-5x218 C-Listing V2.0 int 2,1 3,5 46,9 125,3 239,6 ____,_
" " C-Listing V2.0 long 4,8 8,1 113,8 304,4 583,1 18210,0
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
T800 (20MHz) Occam V.0.88 Occam V.1.0 (32Bit) 0,x 0,x 0,3 0,8 1,5 45,5
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
386DX40 128K Cache Quick C 1.0 BasBenc2.C (long) all optimizations for speed 3,1 84,9
+ CoPro " BasBenc1.C (float) 8,2 240,6
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
RasPi 2B (0,9GHz) Python 3.4.2 prime2.py 0,01 0,02 0,21 0,53 0,93 28,48
" pypy3-2.4.0 " 0,14 1,45
" C-Cortex-A7 (Chromatix) 0,002 0,004 0,007 0,183
" gcc " 0,005 0,013 0,025 0,804
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
Arduino Nano V3 Sketch V1.8.5 ~C(V2) int 0,032 0,055 0,80 2,15 4,11
(16MHz ATmega328) ~C(V2) long 0,094 0,163 2,33 6,38 11,91 366,4
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
PC,i7-8700,3.2GHz LuaJIT ~PASCAL(V2) 0,005 0,010 0,2 0,5 0,9 26,0 <= ms !!!
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
MicroVAX 3100/90 GCC for VAX C(V2) (int32) 2,48 4,17 53,61 139,26 262,22 7653,1 <= ms !!!
" C(V2) (int64) 13,24 22,61 312,63 826,16 1570,51 46712,3 <= ms !!!
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
The origin of the table starts back around 1980/81 when I played on a SYM-1 with 4K RAM and Synertek-BASIC (=Microsoft). The benchmark program simply calculates prime number gaps: "BasBenc1"
Code:
1 REM
2 REM B A S I C - B E N C H
3 REM
4 REM Das Programm testet, ob es im Bereich [3..A] der natürlichen
5 REM Zahlen zwei aufeinander folgende Primzahlen P1 < P2 gibt, deren
6 REM Differenz größer oder gleich B ist ( P2 - P1 >= B ).
7 REM
8 REM
10 ZS = 3 : INPUT A,B
20 FOR C = 3 TO A STEP 2
30 FOR D = 3 TO SQR(C) STEP 2
40 IF INT(C/D)*D = C THEN 80
50 NEXT D
60 IF C-ZS >= B THEN PRINT C,ZS,C-ZS : GOTO 10
70 ZS = C
80 NEXT C
90 PRINT " KEINE LOESUNG " : GOTO 10
I tried to gain more speed using the ability of MS-Basic to deal with integers instead of floats:
Code:
1 REM Basic-Bench á la SYM etc.
2 REM **** Integerversion ****
10 ZS% = 3: INPUT A%,B%
20 FOR C% = 3 TO A% STEP 2
30 FOR D% = 3 TO SQR(C%) STEP 2
40 IF (C%\D%)*D% = C% THEN 80
50 NEXT D%
60 IF C%- ZS% >= B% THEN PRINT C%,ZS%,C%-ZS%: GOTO 10
70 ZS% = C%
80 NEXT C%
90 PRINT "keine Lösung gefunden !": GOTO 10
Using modulo instead of (C%\D%)*D% was the last step:
Code:
1 REM Basic-Bench á la SYM etc.
2 REM *** Integerversion + Modulofunktion ***
10 ZS% = 3: INPUT A%,B%
20 FOR C% = 3 TO A% STEP 2
30 FOR D% = 3 TO SQR(C%) STEP 2
40 IF C% MOD D% = 0 THEN 80
50 NEXT D%
60 IF C%- ZS% >= B% THEN PRINT C%,ZS%,C%-ZS%: GOTO 10
70 ZS% = C%
80 NEXT C%
90 PRINT "keine Lösung gefunden !": GOTO 10
On a 6809 system running FLEX-9 I could try more languages: Basic, Pascal, and C. The first Pascal attempt was a straight translation:
Code:
program BENCH1( INPUT,OUTPUT );
{ Programm ist Pascal-Version vom Basic-Bench.
Es testet ob es im Bereich 3 bis A zwei aufeinanderfolgende
Primzahlen (p1,p2) gibt, so das gilt : p2-p1 >= B }
const prim0 = 3; incr = 2;
var range,mindiff,prim1,prim2,cnt1,cnt2,limit1 : integer;
flag1 : boolean;
begin { main }
range := 0; mindiff := 0; prim1 := prim0; prim2 := prim1; cnt1 := prim0;
while range <= prim0 do begin
writeln; write(' Gebe obere Grenze und minimale Differenz ein : ');
readln( range,mindiff ); writeln
end;
while (cnt1 <= range) and (prim2-prim1 < mindiff) do begin
limit1 := round(sqrt(cnt1));
flag1 := true; cnt2 := prim0;
while (cnt2 <= limit1) and flag1 do begin
flag1 := not( cnt1 mod cnt2 = 0 );
cnt2 := cnt2 + incr
end;
if flag1 then begin
prim1 := prim2 ; prim2 := cnt1
end;
cnt1 := cnt1 +incr
end;
if prim2-prim1 >= mindiff
then writeln(' Ergebnis : ',prim2:8,prim1:8,prim2-prim1:8)
else writeln(' keine Loesung gefunden ')
end.
Then I discovered a method to get around using SQRT():
Code:
program BENCH2( INPUT,OUTPUT );
{ Programm ist Pascal-Version vom Basic-Bench.
Es testet ob es im Bereich 3 bis A zwei aufeinanderfolgende
Primzahlen (p1,p2) gibt, so das gilt : p2-p1 >= B .
Im Gegensatz zur Version BENCH1, ist diese pascaltypisch geschrieben. }
const prim0 = 1; incr = 2;
var range,mindiff,cnt,hiprim,loprim : integer;
function prim(x : integer): boolean;
const step =2; init = 3;
var i : integer;
begin
i := init;
while (( i*i < x ) and ( x mod i <> 0 )) do
i := i + step;
prim := x < i*i ;
end; { of prim }
begin { main }
writeln; write(' Gebe obere Grenze und minimale Differenz ein : ');
readln( range,mindiff ); writeln;
loprim := prim0;
hiprim := prim0;
cnt := prim0;
while (cnt < range) and (hiprim-loprim < mindiff) do begin
cnt := cnt + incr;
if prim(cnt) then begin
loprim := hiprim;
hiprim := cnt
end;
end;
writeln;
if hiprim - loprim >= mindiff
then writeln(' Ergebnis : ',hiprim:8,loprim:8,hiprim-loprim:8)
else writeln(' keine Loesung gefunden ')
end.
The C code using floats is lost, but it should correspond to the first Pascal version. The V2 variant using integers:
Code:
#include <stdio.h>
/* #include <math.h> */
int getnum()
{ char s[80];
gets(s);
return(atoi(s));
}
int prim(x) /* if x is prime return 1 else 0 */
int x;
{ int i = 3;
while ((i*i < x) && (x % i) != 0)
i+=2;
if (x < i*i) return(1);
else return(0);
}
void main()
{ int a,b,i,loprim,hiprim;
printf("\nGeben Sie den oberen Grenzwert ein :");
a = getnum();
printf("\nGeben Sie die minimale Differenz ein :");
b = getnum();
loprim = hiprim = 1;
for (i=3; i <= a && (hiprim-loprim < b); i+=2)
{ if (prim(i))
{ loprim = hiprim; hiprim = i;
}
};
if (hiprim-loprim < b)
printf("keine Loesung gefunden !\n");
else
printf("%12d %12d \n",hiprim,loprim);
}
Using longs:
Code:
#include <stdio.h>
#include <ctype.h>
/* #include <math.h> */
long getnum()
{ char c;
long res=0;
while(isdigit(c=getchar()))
res = res*10+(c & 15);
return(res);
}
int prim(x) /* if x is prime return 1 else 0 */
long x;
{ long i = 3;
while ((i*i < x) && (x % i) != 0)
i+=2;
if (x < i*i) return(1);
else return(0);
}
void main()
{ long a,b,i,loprim,hiprim;
printf("\nGeben Sie den oberen Grenzwert ein :");
a = getnum();
printf("\nGeben Sie die minimale Differenz ein :");
b = getnum();
loprim = hiprim = 1;
for (i=3; i <= a && (hiprim-loprim < b); i+=2)
{ if (prim(i))
{ loprim = hiprim; hiprim = i;
}
};
if (hiprim-loprim < b)
printf("keine Loesung gefunden !\n");
else
printf("%12ld %12ld \n",hiprim,loprim);
}
The latest written version was in VTL02C (thanks to Mike B. and Klaus):
Code:
100 ?="Range = ";
105 A=?
110 ?="min.Diff = ";
115 B=?
120 Z=3
130 C=1
140 C=C+2
150 D=1
160 D=D+2
165 X=C/D
170 #=%=0*210
180 #=C>(D*D)*160
190 #=C>(B+Z)*230
200 Z=C
210 #=A>C*140
220 ?="KEINE LOESUNG"
225 #=260
230 ?=C
240 ?=", ";
250 ?=Z
260 ?=""
270 #=100
If some of you using one or more of the given programs or perhaps a Forth version (!) and doing the necessary adaptations to get it running - post your results and I will add from time to time an entry to the table.
Cheers
Arne