Code archives/3D Graphics - Mesh/DeleteEntity vs. ClearSurface speed test
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
In my shadow system, I needed to make a copy of several meshes every frame so I could manipulate them safely. When I was done manipulating them, I deleted them. I made the copies using addmesh. But was there a faster way? It would seem like deleting the shadow entity and then rebuilding the mesh again would be fastest. But in fact, I discovered using this code that it's 3x faster on my system if I simply clear the surface rather than deleting the mesh and starting over. Anyhow, here's the code, test it for yourself! | |||||
Graphics3D 640,480,16,0 Mesh = CreateSphere() start=MilliSecs() ;---------------------------------------------------------------------------------------------------------------------- For c =1 To 10000 NewMesh1 = CreateMesh() AddMesh Mesh, NewMesh1 FreeEntity NewMesh1 Next ;---------------------------------------------------------------------------------------------------------------------- time1#=MilliSecs()-start start=MilliSecs() ;---------------------------------------------------------------------------------------------------------------------- NewMesh1 = CreateMesh() AddMesh Mesh, NewMesh1 Surface = GetSurface(NewMesh1, 1) For c =1 To 10000 ClearSurface Surface AddMesh Mesh, NewMesh1 Next ;---------------------------------------------------------------------------------------------------------------------- time2#=MilliSecs()-start Print "The second method takes " + (time2# / time1#) + " times as long." |
Comments
None.
Code Archives Forum