FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM 
FB II COMPILER
Consider speed (II)
Considération sur la rapidité d’exécution II
The small program below, uses the scientific functions of sin and cos. It draws a circle of any number of given points entered by the user and plots them out on the screen.
This was my first draft of the program in FB and it uses input and a very ungraceful way to exit the program. However, this is the version that I used to time the program at work on other machines so this is the version that is here.
Timing the program for a 100 point circle:
6100/60 3 min 08 sec < my machine
LC550 2 min 26 sec
7600/120 1 min 55 sec
Quadra650 0 min 57 sec < the winner
The Challenge:
I would like to see (or know) how fast this program will run compiled as a cpuFAT. Running native on a Power Mac, it should then beat the pants off of the Quadra650. Right?
P.S.
Some other program notes:
The program count is not accurate and I don't know why. I correct for the errors up to count 100 but this is a dumb way to do things. If anyone can find the glitch, please let me know what it is.
NOTE: Some lines are (veryvery) long. You may have to put them together before running the program.
' CUT HERE 
WINDOW 1,"Spirograph",(0,0)(500,400)
"start"
PI! = 6.283185307
PRINT % (30,383) "TO EXIT PROGRAM, YOU MUST CLICK MOUSE WHILE DRAWING A CIRCLE"
PRINT % (260,21);:PRINT "HIT RETURN TO DRAW CIRCLE"
PRINT % (2,21);
INPUT "NUMBER OF POINTS IN THE CIRCLE: ";N
PRINT % (260,21);:CLS LINE
PRINT % (260,21) "POINTS COMPLETE:"
PRINT % (2,33) "CLICK MOUSE TO EXIT PROGRAM"
IF N=0 THEN CLEAR:CLS:BEEP:GOTO "start"
IF N=1 OR N=2 OR N=9 OR N=13 OR N=19 OR N=23 THEN "skipH"
IF N=26 OR N=27 OR N=29 OR N=31 OR N=36 OR N=43 OR N=46 OR N=47 OR N=50 THEN "skipH"
IF N=52 OR N=53 OR N=57 OR N=58 OR N=59 OR N=61 OR N=62 OR N=63 OR N=64 OR N=65 OR N=69 OR N=73 THEN "skipH"
IF N=76 OR N=78 OR N=79 OR N=81 OR N=82 OR N=83 OR N=86 OR N=87 OR N=90 OR N=93 OR N=94 OR N=98 OR N=100 THEN "skipH"
'Good count through 100
FOR X! = 0 TO PI! STEP PI! / N
FOR Z! = 0 TO PI! STEP PI! / N
A! = INT (SIN (X!) * 150) + 249
B! = INT (COS (X!) * 149) + 200
C! = INT (SIN (Z!) * 150) + 249
D! = INT (COS (Z!) * 149) + 200
PLOT A!,B! TO C!,D!
IF FN BUTTON STOP
NEXT Z!
PRINT % (373,21);:CLS LINE
H=H+1:PRINT % (375,21) H
"skipH"
NEXT X!
PRINT % (2,33);:CLS LINE
PRINT "CLICK MOUSE TO CLEAR SCREEN"
DO
UNTIL FN BUTTON OR LEN(INKEY$)
CLEAR:CLS:GOTO "start"
The small program below, uses the scientific functions of sin and cos
Andy changed this to work in FB II integer functions. 100 iterations on my 604e 200 took 77 ticks. The modified program is shown below.
Using integer math, FB II is _very_ fast. While there is not yet an equivalent to FB II's USR scientific functions, we were able to recompile in FB^3 using floating point calculations. This was not as fast as integer math, but showed a marked improvement over FB II's BCD calcs.
6100/60 3 min 08 sec < my machine
LC550 2 min 26 sec
7600/120 1 min 55 sec
Quadra650 0 min 57 sec
604e 200 77 ticks (using integer functions) < the winner
604e 200 83 ticks (using floating point, but recompiled in PPC code)
The end result is that PPC math in FB^3 runs at about the same speed as integer math in FBII. (I was impressed!)
'
WIDTH _noTextWrap
WINDOW 1,"Spirograph",(0,0)(500,400)
TEXT ,,,0
"start"
TwoPI! = 6.283185307
PRINT % (2,21);
INPUT "Number of Pts, < 2 to exit: ";N
CLS
IF N <= 1 THEN STOP
'******* Integer *********
t&=FN TICKCOUNT
H=0
iLoops = (256*100)/N
COLOR _zBlue
FOR x = 0 TO 25500 STEP iLoops
A = (USR _Sine(x/100) 150)/256 + 249
B = (USR _Cosine(x/100) * 149)/256 + 200
FOR z = 0 TO 25500 STEP iLoops
C = (USR _Sine(z/100) 150)/256 + 249
D = (USR _Cosine(z/100) * 149)/256 + 200
PLOT A,B TO C,D
IF FN BUTTON STOP
NEXT
H=H+1 : PRINT % (360,21) H
NEXT
t&=FN TICKCOUNTt&
PRINT % (400,21) t&;" ticks";
'******* Float *********
t&=FN TICKCOUNT
H=0
COLOR _zRed
loops! = TwoPI!/N
FOR X! = 0 TO TwoPI! STEP loops!
A = SIN (X!) * 150 + 249
B = COS (X!) * 149 + 200
FOR Z! = 0 TO TwoPI! STEP loops!
C = SIN (Z!) * 150 + 249
D = COS (Z!) * 149 + 200
PLOT A,B TO C,D
IF FN BUTTON STOP
NEXT Z!
H=H+1 : PRINT % (360,36) H
NEXT X!
COLOR _zBlack
t&=FN TICKCOUNTt&
PRINT % (400,36) t&;" ticks";
GOTO "start"
It took 1 min 30 sec on my Power Computing Power Center 150. This program would probably be sluggish even in native Power PC code. It calls the trig functions 40000 times to draw a 100 point circle.
I changed your example to remove these trig function calls from the main loop. This version only takes 4 seconds to draw 100 points. In general I have always been able to keep from having to call trig functions or doing floating point math in a loop by building a lookup table like the one used in the example below. If you want your program to be speedy only use integer math in loops. A file translation program that originally used floating point math in the main loop took about 4 hours to process a typical file. When I removed all the floating point math from the main loop a typical file processed in less than 1 min.
' CUT HERE 
WINDOW 1,"Spirograph",(0,0)(500,400)
"start"
PI! = 6.283185307
PRINT % (30,383) "TO EXIT PROGRAM, YOU MUST CLICK MOUSE WHILE DRAWING A CIRCLE"
PRINT % (260,21);:PRINT "HIT RETURN TO DRAW CIRCLE"
PRINT % (2,21);
INPUT "NUMBER OF POINTS IN THE CIRCLE: ";N
PRINT % (260,21);:CLS LINE
PRINT % (260,21) "POINTS COMPLETE:"
PRINT % (2,33) "CLICK MOUSE TO EXIT PROGRAM"
IF N=0 THEN CLEAR:CLS:BEEP:GOTO "start"
DIM xArray(100),yArray(100),count1,count2
count1=0
FOR X! = 0 TO PI! STEP PI! / N
xArray(count1) = INT (SIN (X!) * 150) + 249
yArray(count1) = INT (COS (X!) * 149) + 200
INC(count1)
NEXT X!
count1=0 : H = 0
FOR X! = 0 TO PI! STEP PI! / N
x1=xArray(count1) : y1=yArray(count1)
count2=0
FOR Z! = 0 TO PI! STEP PI! / N
x2=xArray(count2) : y2=yArray(count2)
PLOT x1,y1 TO x2,y2
IF FN BUTTON STOP
INC(count2)
NEXT Z!
PRINT % (373,21);:CLS LINE
H=H+1:PRINT % (375,21) H
INC(count1)
NEXT X!
PRINT % (2,33);:CLS LINE
PRINT "CLICK MOUSE TO CLEAR SCREEN"
DO
UNTIL FN BUTTON OR LEN(INKEY$)
CLEAR:CLS:GOTO "start"
On a PowerMac G3/233, running Mac OS 8.1, I got 40 ticks with 68K integer math, and 1160 ticks with 68K BCD math. (Compiled FBII; the "Spirograph" version of the program.) With PPC Floating Point Math (Compiled FB^3, courtesy of Staz  no, I don't have the compiler... just the app) I got 52 ticks!
So, the speed comparison runs; 1160 68K float, 52 PPC float, 40 68K integer, all on the same Mac. Considering the G3 is _not_ known for it's floating point speed, I can't wait to see what this looks like once the PPC integer version is available. I suspect that _most_ of that 40 or 52 ticks is already taken up by QuickDraw drawing the lines, and _not_ by the calculations. So, my "guess" is that PPC integer math would run in the low 30's, that we _won't_ see another 29X speedup. If we did, that'd mean the thing can run in 1.38 ticks...
The 22X speed improvement between 68K and PPC floating point tells me that I _really_ want that FB^3 compiler... even though this is admittedly a "special case" that highlights the differences more than any "normal" program would!
