quick poll - precalc sin & cos or perform every frame ?

BlitzPlus Forums/BlitzPlus Programming/quick poll - precalc sin & cos or perform every frame ?

Craig... Check the code out below. It is the same as above only now we draw 1000 rectangles after our Sin & Cos loops. The results on my machine were....

Where USELOOKUP=0 : Time 1117

Where USELOOKUP=1 : Time 207

This has got be conclusive proof that pre-calcing the Sin & Cos of an angle is still lots faster even when using graphical operations. This is a fair test because software 3D engines usually pre-calc sin & cos and then store the results in another array. This new array is then used to plot each vertex (after perspective correction etc). So this could be considered a real world situation.

[Code]

Graphics 640,480,32,2

N=1000000

Dim Sin2#(360)
Dim Cos2#(360)

For a=0 To 359
Sin2#(a)=Sin(a)
Cos2#(a)=Cos(a)
Next
;Change this to switch test
Const UseLookup=1

starmill = MilliSecs()
If uselookup=0 Then
For t = 1 To N
x1#=Sin#(Rnd(0,359))
x2#=Cos#(Rnd(0,359))
Next
; Now Draw 1000 rectangles
For t=1 To 1000
Rect 50,50,100,100
Next
Else
For t = 1 To N
x1#=Sin2#(Rnd(0,359))
x2#=Cos2#(Rnd(0,359))
Next
; Now Draw 1000 rectangles
For t=1 To 1000
Rect 50,50,100,100
Next
End If

result=MilliSecs() - starmill
Text 0,0,result

Flip
WaitKey()
End

[/Code]