Best way to calc next ^2 value...

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

Looks like mathematical operators (including Shl) are optimized away, but builtin functions such as Log() are not.

Const iterations = 10000000
Return 7 ; 203 ms
Return 1 Shl 13 ; 184 ms
Return Log(30) ; 885 ms
Return 7.6 ; 178 ms
a = 7 : b = 8 : Return a * b ; 317 ms
Return iterations / 678 ; 179 ms


These benchmark results were obtained on a 1.6ghz p4 with Blitz3D 1.90, debug mode disabled.

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"

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