Best way to calc next ^2 value...

Blitz3D Forums/Blitz3D Programming/Best way to calc next ^2 value...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Added test_empty() and test_ceil() for more information.

Results (Athlon XP 1800+, ~1.533GHz):

test_int: 131ms
test_shl: 176ms
test_log: 1106ms
test_float: 150ms
test_var: 163ms
test_constmath: 160ms
test_empty: 123ms
test_ceil: 1478ms

I agree with you that the internal math functions are not replaced by const values.

However after subtracting the loop and call overhead shown by test_empty(), I believe that there is significant variation in the other functions compared to test_int.

test_int: 8ms
test_shl: 53ms
test_log: 983ms
test_float: 27ms
test_var: 40ms
test_constmath: 37ms
test_empty: 0ms (this is the baseline)
test_ceil: 1355ms

From this I'd say that expressions like '1 Shl 13' are not reduced to a constant.

I'll think about a more conclusive test.
Const iterations = 10000000

s = MilliSecs() : For i = 1 To iterations
	test_int()
Next : e = MilliSecs() - s
Print "test_int:   " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_shl()
Next : e = MilliSecs() - s
Print "test_shl:   " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_log()
Next : e = MilliSecs() - s
Print "test_log:   " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_float()
Next : e = MilliSecs() - s
Print "test_float: " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_var()
Next : e = MilliSecs() - s
Print "test_var:   " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_constmath()
Next : e = MilliSecs() - s
Print "test_constmath:   " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_empty()
Next : e = MilliSecs() - s
Print "test_empty: " + e + "ms"

s = MilliSecs() : For i = 1 To iterations
	test_ceil()
Next : e = MilliSecs() - s
Print "test_ceil:  " + e + "ms"

WaitKey() : End

Function test_int#()
	Return 7
End Function

Function test_shl#()
	Return 1 Shl 13
End Function

Function test_log#()
	Return Log(30)
End Function

Function test_float#()
	Return 7.6
End Function

Function test_var#()
	a = 7 : b = 8
	Return a * b
End Function

Function test_constmath#()
	Return iterations / 678
End Function

Function test_empty#()
End Function

Function test_ceil#()
	Return Ceil(3)
End Function