Code: Select all

DIM SHARED AS SINGLE SINE(-10000 TO 10000), COSINE(-10000 TO 10000), ATAN(-25000 to 25000)

dim j as single

FOR j = -25000 to 25000

ATAN(j) = ATN(j/10000)

next j

FOR j = -10000 to 10000

SINE(j) = SIN(j/10000)

next j

FOR j = -10000 to 10000

COSINE(j) = COS(j/10000)

next j

dim ST AS SINGLE

dim as single b

dim i as integer

ST = TIMER

do

b = ATN(rnd)

i += 1

loop until TIMER - ST >= 10

PRINT "ATN:";i

i = 0

ST = TIMER

do

b = SIN(rnd)

i += 1

loop until TIMER - ST >= 10

PRINT "SIN:";i

i = 0

ST = TIMER

do

b = COS(rnd)

i += 1

loop until TIMER - ST >= 10

PRINT "COS:";i

PRINT

i = 0

ST = TIMER

do

b = ATAN(INT(rnd*10000))

i += 1

loop until TIMER - ST >= 10

PRINT "ATAN:";i

i = 0

ST = TIMER

do

b = SINE(INT(rnd*10000))

i += 1

loop until TIMER - ST >= 10

PRINT "SINE:";i

i = 0

ST = TIMER

do

b = COSINE(INT(rnd*10000))

i += 1

loop until TIMER - ST >= 10

PRINT "COSINE:";i

sleep

Turns out it isn't that much faster. Here are my results in calculations/sec:

ATN: 970,491.8

SIN: 963,806.3

COS: 970,074.9

ATAN: 1,003,734.7

SINE: 998,793.1

COSINE: 1,010,858.3

Note: The arrays are dimensioned for my min and max values. They might differ for other implementations.

Any way to optimize trig functions further or differently?