Optimisations

Blitz3D Forums/Blitz3D Programming/Optimisations

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.

Becky Rose, take care with your tests. You are using the same variable in the sum and in the for loop, so you are doing wrong calculations.

EDITED: Sorry, i was checking wrong. My code only shows that it is faster not to use the "for" variables to check things, xDDD

This should be the correct code. Faster anyway, but no so much:

;Conditional Checking (faster to test a float versus a float)
n#=0.0
start=MilliSecs()
For j=1 To 10000000
	If n>1.0
	EndIf
Next
Print "Testing 1.0 : "+(MilliSecs()-start)

n#=0.0
start=MilliSecs()
For j=1 To 10000000
	If n>1
	EndIf
Next
Print "Testing 1   : "+(MilliSecs()-start)

;Addition Test (faster to add a hard coded integer to a float)
n#=0.0
start=MilliSecs()
For j=1 To 10000000
	n=n+1.0
Next
Print "Adding 1.0 : "+(MilliSecs()-start)

n#=0.0
start=MilliSecs()
For j=1 To 10000000
	n=n+1
Next
Print "Adding 1   : "+(MilliSecs()-start)

;Addition Test (faster to add a variable integer to a float)
n#=0.0
o#=1.0
start=MilliSecs()
For j=1 To 10000000
	n=n+o
Next
Print "Adding var#: "+(MilliSecs()-start)

n#=0.0
p=1
start=MilliSecs()
For j=1 To 10000000
	n=n+p
Next
Print "Adding var : "+(MilliSecs()-start)