I'm trying to test the CBASIC-80 from Digital Research. This is a compiled version of BASIC. The Z-80 is the C-128 runs more or less at 2Mhz, just like the 8502 in fast mode.
Here is the C-128 program:
10 fast:t=ti 20 for a=1 to 1000:b=a*a:f=99 30 e=int(b/10):e=b-e*10:b=int(b/10) 40 if e>f then 70 50 if b=0 then print a;"=";a*a:goto 70 60 f=e:goto 30 70 next a 80 print (ti-t)/60 It calculate the square of 1000 first numbers and test if the result is in ascending order. In fact, the program doesn't matter.
Here is the same program in CBASIC:
20 FOR A=1 TO 1000:B=A*A:F=99 30 E=INT(B/10):E=B-E*10:B=INT(B/10) 40 IF E>F THEN 70 50 IF B=0 THEN PRINT A;"=";A*A:GOTO 70 60 F=E:GOTO 30 70 NEXT A The two program are exactly the same, except for the time calculation.
In C-128 mode, the program runs in 57 sec. While the CP/M version runs in 4 min 56 sec. Almost 5 time slower than the C-128!! This is because of the C-128 or a compile switch? I don't know exactly.
But the precision is very good. Do you remember the little Test program? The program calculate: 1.9999999837. It's much better than the C-128
One difference is that BASIC 7.0 used 40-bit floating point numbers while CBASIC used 64-bit ones, like you noted. That slows down. Otherwise it's hard to say without taking it apart to see what it is actually doing. Maybe it is calling kernal routines that switches to 8502 mode and back. You could try removing the print to see if it makes a big difference.
Couple of things to keep in mind... C-BASIC is compiled down to p-code, not native Z-80 assembly. It's similar to Blitz! or UCSD Pascal.
You'll get (or should get) better performance out of BASCOM, which is the Microsoft BASIC compiler. It uses identical syntax as MS BASIC-80 that's shipped with most distributions of CP/M. It's v5.21 I think.