I thought I would expand this conversation by using a classic benchmark, the Sieve of Erathosenes.
I know it's an old chestnut, but it is commonly used to see how a language does a few things.
I tried it first with TI-BASIC. I used the MSX version from Rosetta code and fixed a few things so it would run on the TI-99
100 REM Eratosthenes Sieve
110 REM for TI BASIC
120 REM ******************
130 REM MSX BRRJPA
140 INPUT "Search until: ":L
150 DIM P(1500)
160 FOR N=2 TO SQR(L+1000)
170 IF P(N)<>0 THEN 210
180 FOR K=N*N TO L STEP N
190 LET P(K)=1
200 NEXT K
210 NEXT N
220 FOR N=2 TO L
230 IF P(N)<>0 THEN 250
240 PRINT N;
250 NEXT N
I use 1000 for the input value because it takes along time. The big shock for me was that XB was slower than TI-BASIC.
Then of course I did a version for Forth and tested it on Turbo Forth and Camel99 a couple of ways.
Here is that code which is also from Rosetta Code but slightly modified by me.
I don't agree with the way they did the looping in the WHILE statement. It's a slow thing to have multiplication to calculate a loop
I will see if I can make it more like the C version...
\ Sieve of Erathosenes in Forth
\ Tested with TurboForth and CAMEL99 Forth
\ array calculators
: @ ( n addr -- ? ) + C@ ;
: ! ( n addr -- ) + C! ;
: ERASE ( addr n -- ) 0 FILL ;
: FREEMEM ( -- n) FF00 HERE - ;
: ?MEM ( n -- ) FREEMEM OVER < ABORT" Out of memory" ;
\ byte array uses unallocated memory at 'HERE'
: PRIMES ( n -- )
CR ." Running..."
HERE OVER ERASE
1 0 HERE ! \ mark as prime like 'C' version
1 1 HERE !
2 \ start at 2
2DUP DUP * >
DUP HERE @ 0=
IF 2DUP DUP *
1 I HERE !
CR ." Complete."
." Primes: " 2 DO I HERE @ 0= IF I . THEN LOOP
And here are the timings. BASIC can't allocate enough memory for more than about 1500 elements because of the big floating point numbers so I limited it to 1000.
X BASIC 14.3 secs
TI BASIC 11.9
CAMEL99 ITC 10.28
CAMEL99 DTC 7.25
I would be interested in seeing the GCC results using the Rosetta code version or something similar.