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

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

Interesting Graig. I ran your code and my swap file kicked in (only 256 MB Ram). Not surprising considering the large numbers involved here.

Three points to your code....

1. Sin & Cos only need an angle of 0 to 359 degrees so it is rather unfair trying to get the Sin & Cos of an angle like 35999999. Havent tried using radians so this maybe a better test.

2. We only need to Dim the arrays of 360 elements because that is all people use. An angle of 361 degrees is the same as 1 degree.

3. The important thing is the iterations part in your For...Loops because this is what takes the time to process the results.

I've modified your code below which now uses 1,000,000 iterations. Run it once then change your USELOOKUP variable to a 1. The results on my 2GHz Celeron were.....

Where USELOOKUP=0 : Time = 1179 Millisecs

Where USELOOKUP=1 : Time = 167 Millisecs

One interesting point to note is that using lookup tables on my computer was only approx 9 times faster. This may have something to do with the RND() function that you have included.


[Code]
Graphics 640,480,32,2

;Lookup Table
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=0

starmill = MilliSecs()
If uselookup=0 Then
For t = 1 To N
x1#=Sin#(Rnd(0,359))
x2#=Cos#(Rnd(0,359))
Next
Else
For t = 1 To N
x1#=Sin2#(Rnd(0,359))
x2#=Cos2#(Rnd(0,359))
Next
End If

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

Flip
WaitKey()
End

[/Code]