Hi Folks, this article I am working on is a WIP so I need your input:
Quote: "The Need for Speed. A test of how best to work with object positions
I have been looking into how best to use DBPRO positions to boost the performance of my game later on as its scale increases. It is not always about speed of performance, sometimes it is more important to focus on convenience; but these questions and statistics are based on performance interests. There are other areas of code that slow things down, but usually with games, objects and their positions are the main focus.
How do you store your positions for your 3d objects, sprites and entities?
Some of you guys who are fortunate enough to have completed a medium to large game with DBPRO already have some experience to provide an answer according to kind of measures to use for calculating and manipulating positions. If not, then how are you doing it?
I made an attempt to create a test program to monitor the performance of position storage functions, and the results are quite interesting. The statistics found are only so because it is small program with no conflicting issues between plugins, content, user input and code; but is it not accurate enough?
The program tests the following float3 storage locations and performs a basic calculation on them, along with creation of the memory.
--------------------------------------------------------
UDT array
3 arrays (x,y,z)
Memblock
Memory Bank (Matrix1)
Mike Net (Dark Net) Packet
Vector
3D Object
3D Limb
Sprite (2D)"
------------------------------------------------------
View the article...
Feedback is desired as I can only test on one machine and the article is currently heavily opinionated.
Run the test (Matrix1 & DarkNet 2 required), and press spacebar to pause just at the desired test interval. (Send a screenshot if you would like to help support the research):
UDTs, Variables and Arrays ( when not used with Add to stack or Inserts etc ) where created more quickly and performed faster calculations than the others. Second where memblocks and banks, with memblocks providing more speed, and banks providing more quantity. Third where network packets and object/camera/sprite expressions; last by a long shot; Vectors and Array/Stack/Queue inserts.
Edit: Added camera read and write: Result shows camera writing [Position Camera N, 0, 0, 0] takes up to 20 times longer than variable writing; so should only be used as few times as possible.
` Chris Tate - Position storage test
` Spacekey to pause
`======================
Type Pos
x#, y#, z#
Endtype
Dim Pos() as Pos
Dim X() as Float : Dim Y() as Float : Dim Z() as Float
Global Ticks as Double Integer
Global Ms as Double Integer
Global MemTime as Double Integer
Global BankTime as Double Integer
Global VecTime as Double Integer
Global ArrTime as Double Integer
Global ArrSeriesTime as Double Integer
Global IsFirstTry as Boolean = 1
Sync On : Sync Rate 0 : Make Object Cube 1, 2 : Sync
Get Image 1, 0, 0, 1, 1
Sprite 1, -1, -1, 1
//==============================================================
Set Text Font "Verdana" : Set Text Size 12 : Color Backdrop 0x001020
mn Start 0, 0
Do
Print "Position Storage Performance Test"
Print "==========================================================="
If IsFirstTry = 0
Ticks = PerfTimer() : Empty Array Pos : ArrTime = PerfTimer() - Ticks
Ticks = PerfTimer() : Empty Array X() : Empty Array Y() : Empty Array Z() : ArrSeriesTime = PerfTimer() - Ticks
MemTime = 0 : BankTime = 0 : VecTime = 0
For ID = 1 to 255
If Memblock Exist(ID) = 0 Then Make Memblock ID, 1
Next ID
For ID = 1 to 255
Ticks = Perftimer() : Delete Memblock ID : MemTime = MemTime + (PerfTimer() - Ticks )
Ticks = Perftimer() : Delete Bank ID : BankTime = BankTime + (PerfTimer() - Ticks )
Ticks = Perftimer() : Delete Vector3 ID : VecTime = VecTime + (PerfTimer() - Ticks )
Next ID
Print "Deletion"
Print "-----------------------------------------------------------"
Print "255x UDT Array deletion time: "; ArrTime; " ticks"
Print "-----------------------------------------------------------"
Print "255x Array Series deletion time: "; ArrSeriesTime; " ticks"
Print "-----------------------------------------------------------"
Print "255x Memblock deletion time: "; MemTime; " ticks"
Print "-----------------------------------------------------------"
Print "255x Bank deletion time: "; BankTime; " ticks"
Print "-----------------------------------------------------------"
Print "255x Vector deletion time: "; VecTime; " ticks"
Print "-----------------------------------------------------------"
Else
IsFirstTry = 0
EndIf
Print "==========================================================="
Print "Creation"
Print "-----------------------------------------------------------"
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Add To Stack Pos() : Pos().x# = Pos().x# + I
Pos().y# = Pos().y# + I : Pos().z# = Pos().z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Dynamic UDT Array creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Empty Array Pos()
Ms = Timer() : Ticks = PerfTimer()
Dim Pos(255) as Pos
For I = 1 to 255
Pos().x# = Pos().y# + I : Pos().y# = Pos().y# + I : Pos().z# = Pos().z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT Array creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
Dim X(255) as Float : Dim Y(255) as Float : Dim Z(255) as Float
For I = 1 to 255
X(I) = X(I) + I : Y(I) = Y(I) + I : Z(I) = Z(I) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Series of array creations time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Make Memblock I, 4 * 3 : Write Memblock Float I, 0, Memblock Float( I , 0) + I
Write Memblock Float I, 4, Memblock Float( I , 4) + I : Write Memblock Float I, 8, Memblock Float( I , 8) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Memblock creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
RecvPacket = mn Create Packet() : mn Set Memory Size RecvPacket, 8
mn Add Float RecvPacket, 0
mn Set Cursor RecvPacket, 0
Ms = Timer() : Ticks = PerfTimer()
Packet = mn Create Packet() : mn Set Memory Size Packet, 3 * 4 * 255
For I = 1 to 255
mn Add Float Packet, mn Get Float( RecvPacket ) + I : mn Set Cursor RecvPacket, 0
mn Add Float Packet, mn Get Float( RecvPacket ) + I : mn Set Cursor RecvPacket, 0
mn Add Float Packet, mn Get Float( RecvPacket ) + I : mn Set Cursor RecvPacket, 0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Network packet creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Make Bank I, 4 * 3 : Write Bank Float I, 0, Bank Float( I , 0) + I
Write Bank Float I, 4, Bank Float( I , 4) + I : Write Bank Float I, 8, Bank Float( I , 8) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Bank creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null = Make Vector3( I ) : Set Vector3 I, X Vector3( I ) + I, Y Vector3( I ) + I, Z Vector3( I ) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Vector3 creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
X# = X# + I : Y# = Y# + I : Z# = Z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Variable creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Location as Pos : Location.X# = Location.X# + I : Location.Y# = Location.Y# + I : Location.Z# = Location.Z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT variable creation time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Print "==========================================================="
Print "Modification"
Print "-----------------------------------------------------------"
Ms = Timer() : Ticks = PerfTimer()
For I = 0 to 254
Pos(I).y# = Pos(I).y# + I : Pos(I).z# = Pos(I).z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT Array modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
X(I) = X(I) + I : Y(I) = Y(I) + I : Z(I) = Z(I) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Series of array modifications time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
iPos = (I-1) * 12
Write Memblock Float I, 0, Memblock Float( I , 0) + I
Write Memblock Float I, 4, Memblock Float( I , 4) + I : Write Memblock Float I, 8, Memblock Float( I , 8) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Memblock modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
RecvPacket = mn Create Packet()
mn Add Float RecvPacket, 0
Ms = Timer() : Ticks = PerfTimer()
mn Set Cursor RecvPacket, 0
mn Set Cursor Packet, 0
For I = 1 to 255
iPos = (I-1) * 12
mn Set Cursor Packet, iPos : mn Add Float Packet , mn Get Float( Packet ) + I
mn Set Cursor Packet, iPos + 4 : mn Add Float Packet , mn Get Float( Packet ) + I
mn Set Cursor Packet, iPos + 8 : mn Add Float Packet , mn Get Float( Packet ) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Network get value time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
iPos = (I-1) * 12
Write Bank Float I, 0, Bank Float( I , 0) + I
Write Bank Float I, 4, Bank Float( I , 4) + I : Write Bank Float I, 8, Bank Float( I , 8) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Bank modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Set Vector3 I, X Vector3( I ) + I, Y Vector3( I ) + I, Z Vector3( I ) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Vector3 modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Location.X# = Location.X# + I : Location.Y# = Location.Y# + I : Location.Z# = Location.Z# + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT variable modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Position Object 1, Object Position X(1) + I, Object Position Y(1) + I, Object Position Z(1) + I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x 3D object position modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
PositionObject(1,I)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Function based 3D object position modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Sprite 1, Sprite X(1) + I, Sprite Y(1) + I, 1
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Sprite position modification time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Sync
While Spacekey()
Nice Wait 5
Endwhile
Nice Wait 1000 : Set Cursor 0, 0
Print "==========================================================="
Print "Input write"
Print "-----------------------------------------------------------"
Ms = Timer() : Ticks = PerfTimer()
For I = 0 to 254
Pos(I).X# = I : Pos(I).y# = I : Pos(I).z# = I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT Array write time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
X(I) = I : Y(I) = I : Z(I) = I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Series of array write time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Write Memblock Float I, 0, I
Write Memblock Float I, 4, I : Write Memblock Float I, 8, I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Memblock write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
RecvPacket = mn Create Packet()
Ms = Timer() : Ticks = PerfTimer()
mn Set Cursor Packet, 0
For I = 1 to 255
mn Add Float Packet , I
mn Add Float Packet , I
mn Add Float Packet , I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Network write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Write Bank Float I, 0, I
Write Bank Float I, 4, I : Write Bank Float I, 8, I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Bank write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Set Vector3 I, I, I, I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Vector3 write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Location.X# = I : Location.Y# = I : Location.Z# = I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT variable write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Position Object 1, I, I, I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x 3D object position write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Offset Limb 1, 0, I, I, I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x 3D limb position write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Sprite 1, I, I, 1
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Sprite position write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Position Camera 0, 0, 0, 0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x camera position write: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
Print "==========================================================="
Print "Output read"
Print "-----------------------------------------------------------"
Ms = Timer() : Ticks = PerfTimer()
For I = 0 to 254
Null# = Pos(I).X# : Null# = Pos(I).y# : Null# = Pos(I).z#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT Array read time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = X(I) : Null# = Y(I) :Null# = Z(I)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Series of array read time: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Memblock Float( I, 0 )
Null# = Memblock Float( I, 4 )
Null# = Memblock Float( I, 8 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Memblock write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
RecvPacket = mn Create Packet()
Ms = Timer() : Ticks = PerfTimer()
mn Set Cursor Packet, 0
For I = 1 to 255
mn Add Float Packet , I
mn Add Float Packet , I
mn Add Float Packet , I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Network write time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Bank Float( I, 0 )
Null# = Bank Float( I, 4 )
Null# = Bank Float( I, i8 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Bank read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = X Vector3( I )
Null# = Y Vector3( I )
Null# = Z Vector3( I )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Vector3 read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Location.X# : Null# = Location.Y# : Null# = Location.Z#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x UDT variable read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Object Position X( 1 )
Null# = Object Position Y( 1 )
Null# = Object Position Z( 1 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x 3D object position read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Limb Position X( 1, 0 )
Null# = Limb Position Y( 1, 0 )
Null# = Limb Position Z( 1, 0 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x 3D limb position read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null = Sprite X( 1 )
Null = Sprite Y( 1 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Sprite position read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 255
Null# = Camera Position X( 0 )
Null# = Camera Position Y( 0 )
Null# = Camera Position Z( 0 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "255x Camera position read time: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Print "==========================================================="
Print "Conversion"
Print "-----------------------------------------------------------"
Delete Memblock 1
Delete Memblock 2
Delete Memblock 3
iMem1 = 1
iMem2 = 2
iMem3 = 3
Ms = Timer() : Ticks = PerfTimer()
Make Memblock From Array iMem1, X()
Make Memblock From Array iMem2, Y()
Make Memblock From Array iMem3, Z()
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "3 arrays to 3 memblocks: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Delete Memblock iMem1
Delete Memblock iMem2
Delete Memblock iMem3
Ms = Timer() : Ticks = PerfTimer()
iMem1 = Find Free Memblock()
Make Memblock From Array iMem1, X()
iMem2 = Find Free Memblock()
Make Memblock From Array iMem2, Y()
iMem3 = Find Free Memblock()
Make Memblock From Array iMem3, Z()
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "3 arrays to 3 memblocks including find free memblock: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
Make Array From Memblock X(), iMem1
Make Array From Memblock Y(), iMem2
Make Array From Memblock Z(), iMem3
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "3 memblocks to 3 arrays: "; Ms; "ms | "; Ticks; " ticks"
Print "-----------------------------------------------------------"
//--------------------------------------------------------------
MemPacket = mn Create Packet()
Ms = Timer() : Ticks = PerfTimer()
iSize = Get Memblock Size( iMem1 )
mn Set Memory Size MemPacket, iSize
mn Add Memblock MemPacket, Get Memblock Ptr( iMem1 ), iSize, 0
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Memblock to network packet time with no prefix: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
mn Set Cursor MemPacket, 0
Ms = Timer() : Ticks = PerfTimer()
mn Get Memblock MemPacket, Get Memblock Ptr( iMem1 ), iSize, 0
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Network packet to memblock time with no prefix: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
iBank = Find Free Bank()
Delete Memblock iMem1
Make Memblock From Array iMem1, X()
Ms = Timer() : Ticks = PerfTimer()
Make Bank From Memblock iBank, iMem1
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Memblock to bank: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Delete Memblock iMem1
Ms = Timer() : Ticks = PerfTimer()
Make Memblock From Bank iMem1, iBank
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Bank to memblock: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Delete Bank iBank
Delete Memblock iMem1
Sync
While Spacekey()
Nice Wait 5
Endwhile
Nice Wait 1000 : Set Cursor 0, 0
Loop
Function PositionObject( iObj, I )
Position Object iObj, Object Position X(iObj) + I, Object Position Y(iObj) + I, Object Position Z(iObj) + I
EndFunction
Edit: Array Loop demonstration. Count variable faster than Array Count function. Expected, the array count loop is twice as slow as the loop which uses a variable.
`%Project Title%
`ArrayTest.dba
`======================
Dim Value(500) as Float
Dim Item() as Integer
Global Ticks as Double Integer
Global Ms as Double Integer
Do
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to Array Count( Value() )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "500x Array Count loop: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
iCount = Array Count( Value() )
For I = 1 to iCount
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "500x Variable Count loop: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
iCount = Array Count( Value() )
For I = 1 to 500
Array Insert At Bottom Item()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "500x Insert at bottom: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Nice Wait 1000 : Cls : Empty Array Item()
Loop
Edit 2: Datatype calculation loops - Integer and Floats best on x86; faster than booleans, bytes, words and Dwords. Using integers and floats in the same calculation took twice as long. Integers 10-20% faster than floats.
`DataTypeTest
`DataTypeTest.dba
`======================
MyBoolean as Boolean ` 1 Byte
MyByte as Byte
MyWord as Boolean ` 2 Bytes
MyInteger as Integer ` 4 Bytes
MyDWord as DWord ` 4 Bytes
MyFloat as Float ` 4 Bytes
MyDoubleInteger as Double Integer ` 8 Bytes
MyDoubleFloat as Double Float ` 8 Bytes
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
Print " B I N A R Y "
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyBoolean = 1 : MyBoolean = 8 || 4 && MyBoolean
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Boolean binary: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyByte = 1 : MyByte = 8 || 4 && MyByte
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Byte binary: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyWord = 1 : MyWord = 8 || 4 && MyWord
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Word binary: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyInteger = 1 : MyInteger = 8 || 4 && MyInteger
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Integer binary: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyDWord = 1 : MyDWord = 8 || 4 && MyDWord
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "DWord binary: "; Ms; "ms | "; Ticks; " ticks"
Print "========================================================"
Print " M A T H S "
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyByte = 10 : MyByte = MyByte + MyByte - MyByte * MyByte / MyByte
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Byte: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyWord = 10 : MyWord = MyWord + MyWord - MyWord * MyWord / MyWord
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Word: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyDWord = 10 : MyDWord = MyDWord + MyDWord - MyDWord * MyDWord / MyDWord
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "DWord: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyInteger = 10 : MyInteger = MyInteger + MyInteger - MyInteger * MyInteger / MyInteger
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyFloat = 10.0 : MyFloat = MyFloat + MyFloat - MyFloat * MyFloat / MyFloat
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyDoubleInteger = 10 : MyDoubleInteger = MyDoubleInteger + MyDoubleInteger - MyDoubleInteger * MyDoubleInteger / MyDoubleInteger
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Double Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyDoubleFloat = 10 : MyDoubleFloat = MyDoubleFloat + MyDoubleFloat - MyDoubleFloat * MyDoubleFloat / MyDoubleFloat
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Double Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyFloat = 10.0 : MyInteger = -20 : MyFloat = MyFloat + MyInteger - MyFloat * MyInteger / MyFloat
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Float and Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyFloat = 10.0 : MyDWord = 20 : MyFloat = MyFloat + MyDWord - MyFloat * MyDWord / MyFloat
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Float and Dword: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyDoubleFloat = 10.0 : MyDoubleInteger = -20 : MyDoubleFloat = MyDoubleFloat + MyDoubleInteger - MyDoubleFloat * MyDoubleInteger / MyDoubleFloat
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Double Float and Double Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Constant Vs Global Vs Local variables: Global variables slowest. Constants and locals just as fast as each other.
`%Project Title%
`GlobalLocalTest.dba
`======================
Global ValueA as Integer
Global ValueB as Integer
#CONSTANT VALUE_C 3
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
DoGlobalOperation()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Global operation: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
DoLocalOperation()
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
DoGlobalStructureOperation()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Global structure operation: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
DoGlobalLocalStructureOperation(ValueB)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Global structure operation using local expression: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
ValueA = DoLocalStructureOperation(ValueA, ValueB)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Local structure operation: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
ValueA = DoLocalOperationLocalReturn1()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Local structure operation and return local result: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
ValueA = DoLocalOperationLocalReturn2()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Local structure operation and return local result using local keyword: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
ValueA = DoLocalOperationLocalReturn3()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Local structure operation and return local result without declaration: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
ValueA = 3 : ValueB = 4
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
ValueA = DoConstantLocalOperationLocalReturn()
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Local structure operation with constant: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Function DoGlobalOperation()
ValueA = 1 + 2 ^ 10
EndFunction
Function DoLocalOperation()
Local iValue1 as Integer
Local iValue2 as Integer
Local diMs as Double Integer
Local diTicks as Double Integer
iValue1 = 1
//--------------------------------------------------------------
diMs = Timer() : diTicks = PerfTimer()
For I = 1 to 10000
iValue1 = ( iValue2 / 2 ) ^ 2
Next I
diTicks = PerfTimer() - diTicks : diMs = Timer() - diMs
Print "Local operation: "; diMs; "ms | "; diTicks; " ticks"
Print "--------------------------------------------------------"
EndFunction
Function DoGlobalStructureOperation()
ValueA = ( ValueB / 2 ) ^ 2
EndFunction iValue
Function DoGlobalLocalStructureOperation( iValue as Integer )
ValueA = ( iValue / 2 ) ^ 2
EndFunction iValue
Function DoLocalStructureOperation( iValue1 as Integer, iValue2 as Integer )
iValue2 = ( iValue1 / 2 ) ^ 2
EndFunction iValue2
Function DoLocalOperationLocalReturn1()
iValue1 = 3 : iValue2 = 4
iValue2 = ( iValue1 / 2 ) ^ 2
EndFunction iValue2
Function DoLocalOperationLocalReturn2()
Local iValue1 = 3
Local iValue2 = 4
iValue2 = ( iValue1 / 2 ) ^ 2
EndFunction iValue2
Function DoLocalOperationLocalReturn3()
iValue2 = ( iValue1 / 2 ) ^ 2
EndFunction iValue2
Function DoConstantLocalOperationLocalReturn()
iValue2 = ( VALUE_C / 2 ) ^ 2
EndFunction iValue2
Edit: Move Sprite / Move Camera / Move Object Vs NewXYZValue: Mostly 40 ticks for 10 looped operations; however NewXYZValue operations on float variables was the fastest at 14 ticks, limb NewXYZValue operations were the slowest at 60 ticks. Move Sprite/Camera/Object is only best when used once; otherwise variable NewXYZ operations are up to 3 times faster:
`GlobalLocalTest
`NewNValueVsMoveObjectCamera.dba
`======================
`%Project Title%
`GlobalLocalTest.dba
`======================
Make Object Cube 1, 1
Ticks as Double Integer
Ms as Double Integer
Get Image 1, 0, 0, 256, 256
Sprite 1, 0, 0, 1
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
Position Object 1, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
Move Object 1, 1.0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x Move object operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Position Object 1, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = Object Position X(1)
Y# = Object Position Y(1)
Z# = Object Position Z(1)
Position Object 1, NewXValue(X#, 0, 1.0), NewYValue(Y#, 0, 1.0), NewZValue(Z#, 0, 1.0)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue object operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
X# = 0 : Y# = 0 : Z# = 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = NewXValue(X#, 0, 1.0)
Y# = NewYValue(Y#, 0, 1.0)
Z# = NewZValue(Z#, 0, 1.0)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue value operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Position Camera 0, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
Move Camera 1, 1.0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x Move camera operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Position Camera 0, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = Camera Position X(0)
Y# = Camera Position Y(0)
Z# = Camera Position Z(0)
Position Camera 0, NewXValue(X#, 0, 1.0), NewYValue(Y#, 0, 1.0), NewZValue(Z#, 0, 1.0)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue camera operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Offset Limb 1, 0, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = Limb Position X(1,0)
Y# = Limb Position Y(1,0)
Z# = Limb Position Z(1,0)
Offset Limb 1, 0, NewXValue(X#, 0, 1.0), NewYValue(Y#, 0, 1.0), NewZValue(Z#, 0, 1.0)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue limb operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Position Camera 0, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = Camera Position X(0)
Y# = Camera Position Y(0)
Z# = Camera Position Z(0)
Position Camera 0, NewXValue(X#, 0, 1.0), NewYValue(Y#, 0, 1.0), NewZValue(Z#, 0, 1.0)
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue sprite operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Sprite 1, 0, 0, 1
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
Move Sprite 1, 1.0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x Move sprite operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Position Sprite 0, 0, 0, 0
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10
X# = Sprite X(0)
Y# = Sprite Y(0)
Sprite 0, NewXValue(X#, 0, 1.0), NewZValue(Y#, 0, 1.0), 1
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10x NewXYZValue sprite operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Curve Angle Vs Curve Value: Curve Angle 5-6 times slower, although it is best for angles. 1000 operations; Value 100 ticks, Angle 500 - 600 ticks.
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
v# = 180
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 1000
v# = CurveValue( 0.0, v#, 100.0 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "1000x Curve value operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
v# = 180
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 1000
v# = CurveAngle( 0.0, v#, 100.0 )
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "1000x Curve angle operations: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Loops : We all need to work through series of positions; so what is the fastest loop method? With 10000 loops, The For loop at 100 - 155 ticks; the others all score anything between 1000 - 5000 ticks; 10 to 50 times slower due to their update requirements and variable operations. Continuous for loop with variable operations took 500 - 600 ticks, 2 to 9 times faster.
`CurveValueVsAngle
`CurveValueVsAngle.dba
`======================
`MoveVsNewXYZValue
`CurveValueVsDivideValue.dba
`======================
`GlobalLocalTest
`NewNValueVsMoveObjectCamera.dba
`======================
`%Project Title%
`GlobalLocalTest.dba
`======================
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000 For loops: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
I = 0
While I <= 10000
I = I + 1
EndWhile
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000 While loops: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
I = 0
Do
I = I + 1
If I => 10000 Then Exit
Loop
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000 Do loops: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
I = 0
Repeat
I = I + 1
Until I => 10000
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000 Repeat loops: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
T = 0
For I = 0 to 1
I = 0 : T = T + 1 : If T => 10000 Then Exit
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000 Continous for loops: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Inc Vs Addition : Literal Vs Constant : Fastest of each 10000 addition/increment on the Athlon was the integer increased by a literal value or unspecified value (1) at 190 - 210 ticks. Second was an integer incremented by a constant integer at 220 ticks, consistently. Inc Variable increments where 50% faster than Variable + Variable additions. The fastest of the non-constant/literals was [Inc MyInteger, Increment] at 240 - 300 ticks. The slowest were the Float + Float variable, literal and constant additions, all at 450 - 500 ticks.
As stated, increasing a float with an integer or vise-versa is slower than using the same datatype. On one occasion the Increase Float by integer scored 650 ticks. Increase Integer by float scored 710 ticks. On another occasion they both constantly scored 700 - 740 ticks.
`CurveValueVsAngle
`CurveValueVsAngle.dba
`======================
`MoveVsNewXYZValue
`CurveValueVsDivideValue.dba
`======================
`GlobalLocalTest
`NewNValueVsMoveObjectCamera.dba
`======================
`%Project Title%
`GlobalLocalTest.dba
`======================
#CONSTANT INC_I 5
#CONSTANT INC_F 5.0
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0
For I = 1 to 10000
Inc MyInt
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Inc Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0
For I = 1 to 10000
Inc MyFloat#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Inc Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0 : Increment = 5
For I = 1 to 10000
Inc MyInt, Increment
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Variable Inc Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0 : Increment# = 5.0
For I = 1 to 10000
Inc MyFloat#, Increment#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Variable Inc Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0
For I = 1 to 10000
Inc MyInt, 5
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Literal Inc Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0
For I = 1 to 10000
Inc MyFloat#, 5.0
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Literal Inc Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0
For I = 1 to 10000
Inc MyInt, INC_I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Constant Inc Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0
For I = 1 to 10000
Inc MyFloat#, INC_F
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Constant Inc Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0 : Increment = 5
For I = 1 to 10000
MyInt = MyInt + Increment
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Variable Addition Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0 : Increment# = 5.0
For I = 1 to 10000
MyFloat# = MyFloat# + Increment#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Variable Addition Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0 : Increment = 5
For I = 1 to 10000
MyInt = MyInt + Increment
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Literal Addition Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyFloat# = 0.0 : Increment# = 5.0
For I = 1 to 10000
MyFloat# = MyFloat# + Increment#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Literal Addition Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyInt = MyInt + INC_I
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Constant Addition Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 10000
MyFloat# = MyFloat# + INC_F
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Constant Addition Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 0 : MyFloat# = 5.0
For I = 1 to 10000
Inc MyInt, MyFloat#
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Inc Integer with Float: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
MyInt = 5 : MyFloat# = 0.0
For I = 1 to 10000
Inc MyFloat#, MyInt
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "10000x Inc Float With Integer: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Instance Vs Clone Vs Make Object From Limb Vs Add Limb : All clone and instance commands occur at the same speed, although there will be a difference capabilities. Deleting cloned/instance objects 5 - 10 times faster than deleting regular objects. Deleting an object with 100 limbs twice as fast as deleting 100 objects - 2 ms vs 4 ms. Make object from limb - 400 ms, slow compared to Add Limb and Append Limb, 120 ms. Delete 100 limbs took 3 ms on the Athlon + NVidea GeForce 8400 computer.
`InstanceVsCloneVsLimbToObjectVsAddLimb
`LimbsCloneInstanceEtc.dba
`======================
`CurveValueVsAngle
`CurveValueVsAngle.dba
`======================
`MoveVsNewXYZValue
`CurveValueVsDivideValue.dba
`======================
`GlobalLocalTest
`NewNValueVsMoveObjectCamera.dba
`======================
`%Project Title%
`GlobalLocalTest.dba
`======================
#CONSTANT INC_I 5
#CONSTANT INC_F 5.0
Ticks as Double Integer
Ms as Double Integer
Make Object Sphere 1, 1
Make Object Sphere 2, 1, 32, 32 : Make Mesh From Object 1, 2
Sync On : Sync Rate 0
Do
For I = 3 to 110
If Object Exist(I) Then Delete Object I
Next I
//--------------------------------------------------------------
Ms = Timer()
Obj = Find Free Object()
Make Object Obj, 1, 0
For I = 1 to 100
Add Limb Obj, I, 1
Next I
Ms = Timer() - Ms
Print "100x Add Limbs: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer()
For I = 1 to 100
Make Object From Limb I+10, Obj, I
Next I
Ms = Timer() - Ms
Print "100x Make object from limb: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
Ms = Timer()
For I = 1 to 100
Delete Object I+10
Next I
Ms = Timer() - Ms
Print "Delete 100 objects with 0 extra limbs: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
Ms = Timer()
Delete Object Obj
Ms = Timer() - Ms
Print "Delete single object with 100 limbs: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
Print "--------------------------------------------------------"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer()
For I = 1 to 100
Clone Object I+10, 1
Next I
Ms = Timer() - Ms
Print "Clone 100 objects: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
For I = 1 to 100
Delete Object I+10
Next I
//--------------------------------------------------------------
Ms = Timer()
For I = 1 to 100
Clone Object I+10, 1, 1
Next I
Ms = Timer() - Ms
Print "Clone 100 shared objects: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 100
Delete Object I+10
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Delete 100 shared objects: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 100
Instance Object I+10, 1
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Instance 100 shared objects: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
Ms = Timer() : Ticks = PerfTimer()
For I = 1 to 100
Delete Object I+10
Next I
Ticks = PerfTimer() - Ticks : Ms = Timer() - Ms
Print "Delete 100 instanced objects: "; Ms; "ms | "; Ticks; " ticks"
Print "--------------------------------------------------------"
//--------------------------------------------------------------*
Obj = Find Free Object()
Make Object Obj, 1, 0
For I = 1 to 100
Add Limb Obj, I, 1
Next I
//-----
Ms = Timer()
For I = 1 to 100
Remove Limb Obj, 1
Next I
Ms = Timer() - Ms
Print "Delete 100 limbs: "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
//--------------------------------------------------------------
Ms = Timer()
Obj = Find Free Object()
Make Object Obj, 1, 0
For I = 1 to 100
Append Limb Obj, 1
Next I
//--------------------------------------------------------------*
Ms = Timer() - Ms
Print "Add limb without specifying id or name"; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
Delete Object Obj
//--------------------------------------------------------------
Ms = Timer()
Obj = Find Free Object()
Make Object Obj, 1, 0
For I = 1 to 100
Append Limb Obj, 1, "Name"
Next I
//--------------------------------------------------------------*
Ms = Timer() - Ms
Print "Add limb without specifying id "; Ms; "ms | "; Ms / 1000.0; " Seconds"
Print "--------------------------------------------------------"
Delete Object Obj
Sync : Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop
Sync Objects Vs Sync Limbs | Move Limbs Vs Move Object : In the tests, whether there are 1000 limbs or objects in the view, the render time is the same; the result was 3-4 FPS. Moving 1000 objects was twice as fast as moving 1000 limbs individually. Moving 1000 limbs individually could not be compared to moving their parent object:
`Sync Objects
`Sync Objects Test.dba
`======================
`InstanceVsCloneVsLimbToObjectVsAddLimb
`LimbsCloneInstanceEtc.dba
`======================
`CurveValueVsAngle
`CurveValueVsAngle.dba
`======================
`MoveVsNewXYZValue
`CurveValueVsDivideValue.dba
`======================
`GlobalLocalTest
`NewNValueVsMoveObjectCamera.dba
`======================
`%Project Title%
`GlobalLocalTest.dba
`======================
#CONSTANT INC_I 5
#CONSTANT INC_F 5.0
Ticks as Double Integer
Ms as Double Integer
Sync On : Sync Rate 0
Do
//-------------------------------------------------
For I = 1 to 1000
Make Object Cube I, 1
Next I
//--------
For I = 1 to 20
Print "1000 Object Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Sync
Next I
Nice Wait 1000
For I = 1 to 1000
Delete Object I
Next I
//-------------------------------------------------
//-------------------------------------------------
Make Object Cube 1, 1
Make Mesh From Object 1, 1
For I = 1 to 1000
Add Limb 1, I, 1
Next I
Delete Mesh 1
//--------
For I = 1 to 20
Print "1000 Limb Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Sync
Next I
Delete Object 1
//-------------------------------------------------
For I = 1 to 1000
Make Object Cube I, 1
Next I
//--------
For I = 1 to 500
For ID = 1 to 1000
Position Object ID, 0.0, ID, 0.0
Next ID
Print "Position 1000 Objects Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Sync
Next I
Nice Wait 1000
For I = 1 to 1000
Delete Object I
Next I
//-------------------------------------------------
//-------------------------------------------------
Make Object Cube 1, 1
Make Mesh From Object 1, 1
For I = 1 to 1000
Add Limb 1, I, 1
Next I
Delete Mesh 1
//--------
Cls
For I = 1 to 500
For ID = 1 to 1000
Offset Limb 1, ID, 0.0, ID, 0.0
Next ID
Print "Offset 1000 Limbs Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Sync
Next I
For I = 1 to 50
For ID = 1 to 1000
Position Object 1, 0.0, ID, 0.0
Next ID
Print "Move 1000 Limbs using the parent object Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Next I
For I = 1 to 50
For Level = 1 to 1000
For ID = 1 to 1000
Offset Limb 1, ID, 0.0, Level, 0.0
Next ID
Next Level
Print "Move 1000 Limbs individually Sync FPS: "; Screen Fps()
Print "==================================================" : Set Cursor 0, 0
Sync
Next I
Delete Object 1
//-------------------------------------------------
Nice Wait 1000 : Set Cursor 0, 0 : Cls
Loop