Which is Faster?
Blitz3D Forums/Blitz3D Programming/Which is Faster?
| ||
Is using Types Faster than Arrays??? Im trying to make a new tile editor for a 2d game im working on but I have noticed that having a large amount of tiles slows blitz down alot, Im using arrays I was thinking about changin to types for the tile info, but not sure how much faster it would be.. |
| ||
If anything is slowing you down it's displaying those tiles :). |
| ||
Not enough that they would make the difference you are probably hoping for. Try looking at your code to see where major bottlenecks are. |
| ||
Recently, I read (either here or at Blitzcoder) that arrays are apparantly faster than types. |
| ||
Yeah.make sure you are not drawing tiles that are off-screen. BTW... whys this in 3d? |
| ||
AFAIK,n=type\value is slower then n=value(index) ;or n=value[index] I wouldn't worry about that though. Like ^they^ all said, clip your tiles. |
| ||
Actually I'm working on QuadTree Terrain Mesh, and i can say that the array are more slower than the type for some operations, and if I need a array of type, I use a memory bank to stock then handle of the type ... Now I always use Handle and Objects commands when i use type, with this you don't need to uses for each .... But It's not really the type or the array who slow down you editor, it s the number of tile. Blitz don't like to have a lot of thing (mesh, sprite or other thing)to manage in memory that all. Just try this: make a simple scence with 1 objects of 10000 Traingle, and an other with 5000 objects with 2 Triangles. |
| ||
Your right, I just tested. I had to jack up the iterations really high to see a difference, and even then it was pretty miniscule. *edit #1* hold that thought-- I just realized my test is way off.... re-editing after I fix it XD *edit* *edit #2* NM, Fixed it- I was right. This test has arrays coming up faster then types, gonna give it one more go with winamp and crap all turned off * test... Type blah Field value% End Type b.blah=New blah Dim value(0) iterations=100000000 ;start test Print "array access" t=MilliSecs() For i=0 To iterations n=value(0) Next t=MilliSecs()-t Print t+" ms" Print "" Print "type access" t=MilliSecs() For i=0 To iterations n=b\value% Next t=MilliSecs()-t Print t+" ms" Print "" Print "Press Any Key" WaitKey End *edit #3* ya arrays slightly faster than types......man my brain is on vacation :) */edit* |
| ||
It's not enough to worry about. You need to clean up your code. |
| ||
Yes it's true, but you can't use an array like a type. An array store only 1 type variable, and in blitz you must fixe his size before to use it ... When you acces at one Type, you have more 1 value, and you don't know the size |
| ||
You can redefine arrays. |
| ||
So look at this, it s real simulation of type by an array Type blah Field value% Field value2$ End Type Dim value(10000,10000) Dim stringarray$(10000,10000) Print "array access" t=MilliSecs() For i=0 To 10000 n=value(i,j) tt$=stringarray$(i,j) Next t=MilliSecs()-t Print t+" ms" Print "" ; Creating the type Print "Creating type" For i=0 To 10000 b.blah=New blah Next Print "type access" t=MilliSecs() For b.blah = Each blah n=b\value% tt$=b\value2$ Next t=MilliSecs()-t Print t+" ms" Print "" Print "Press Any Key" WaitKey End |
| ||
Hmm |
| ||
Type blah Field value% Field value2$ End Type Dim value(10000) Dim stringarray$(10000) Print "array access" t=MilliSecs() For i=0 To 10000 n=value(i) tt$=stringarray$(i) Next t=MilliSecs()-t Print t+" ms" Print "" ; Creating the type Print "Creating type" For i=0 To 10000 b.blah=New blah Next Print "type access" t=MilliSecs() For b.blah = Each blah n=b\value% tt$=b\value2$ Next t=MilliSecs()-t Print t+" ms" Print "" Print "Press Any Key" WaitKey End Why create two arrays with 10000 elements per element in the first dimension when you only need 1. That doesnt make for a very accurate test. |
| ||
Not only that but it takes forever and might not even work on some computers. Thinking about it, that is jsut going to cause a huge pagefile thrashing since your basically requesting the computer open up WAY more memory then alot of systems are going to have for that in array(400 megs). I dunno how that even works internally..... |
| ||
I do this to have real compraison between Type and Array, because it s not the same thing. How you can have this in an array Type Player field name$ field mesh field x#,y#,z# end type You can't, if you want to manage the player with array without type, you must have 5 arrays dim player_name$( ) dim player_mesh( ) dim player_x( ) dim player_y( ) dim player_z( ) So this is why there was 2 arrays |
| ||
you need an array for string and one for float. And you only need as meny elements in the second dimmension as your object has properties. |
| ||
Yes you can, but in all case it s more slower |
| ||
You can use ANOTHER array for integers if your nit picking, but still... the speed gain is so tiny.. Did you even check mmy accurate test code. Yours that I fixed? |
| ||
You can't, if you want to manage the player with array without type, you must have 5 arrays dim player_name$( ) dim player_mesh( ) dim player_x( ) dim player_y( ) dim player_z( ) So this is why there was 2 arrays You don't need 5 arrays. You only need 2 arrays. Dim Player_Name$(amount) Dim Player_Vars(amount, 3) The second array is a two dimensional array. Player_Vars(amount, 0) = mesh Player_Vars(amount, 1) = x Player_Vars(amount, 2) = y Player_Vars(amount, 3) = z or possibly 3 arrays Dim Player_Name$(amount) Dim Player_Mesh(amount) Dim Player_Vars#(amount, 2) The third array is a two dimensional float array. Player_Vars#(amount, 0) = x Player_Vars#(amount, 1) = y Player_Vars#(amount, 2) = z |
| ||
See for your tile editor. Don't draw each tile every frame. Instead, draw the tiles to a large image, larger than the size of the screen. When the image is close to scrolling out the screen, redraw the image, inside it's self (slightly offset off course), and draw the new tiles. SetBuffer ImageBuffer(large_image) use that to select the imagebuffer to be drawn to. Draw the tiles. And only update the large image, when you need to. It's alot faster to draw one large image, then many small ones. Fastest way to do tilemaps in blitz me thinks. Thanks to Shagwana for this info. I'm now using this way on my current tile map system :) |
| ||
okay thanks for all the help.. as for teh imagebuffer idea Im already doing that.. and its give you a slight loading time.. and as for this being in Blitz3d chat thats what I own and thats what im using :P |
| ||
Are you leaving Debug on. I found that debug mode really slows down 2d stuff. |
| ||
I've come up with an AMAZING new optimization I would like to share with all of you.... firstly the FASTEST method of storing data is to carry it written on a piece of paper with you, running (and this is important!) running, TOP... SPEED, down the highway toward the direction of the computer you are attempting to reach with the information. Keep this up untill you reach that computer, then inform the occupants to do the same but to NOT return to computers they have passed. Eventually all the people will die of fatigue and then no one will have to debate issues of speed. I begin the revolution now. |
| ||
Tried it, Shattered - but IMHO......rollerblades are still faster ;) |