PDA

View Full Version : Efficient scripts and housecleaning!?



evenflcw
12-29-2003, 01:22 AM
I just have a few questions to the more experienced programmers concerning good and efficient programming. Some might be silly and some might not be easily answered or easy to give a general reply on. But anyways... :


Not considering the use or time it takes to create them, will large amounts of data make scripts run any slower? (Housed in arrays for example; and I'm not talking about ridiculus amounts that would max out the RAM.)

Is it faster to use several onedimensional arrays instead of a larger multidimensional one?

Are all loops (for(), foreach(), while()) equally fast and can one just choose depending on what type suits the situation best or should one make an extra effort to try and use a particular one?

Does a switch() command run faster than alot of if-else statements?

Is it necessary to nil all variables and arrays at the end of an lscript or does the lscript engine do this by itself?

Thanks in advance!

wiffzack
12-29-2003, 01:51 AM
I don t really know cause i am ls newb. But i think LS is really fast.
I want to write the fastest possible scripts too :).

The while loop should be the fastest.
Switch should be faster then if else if...
But i will test the speed of LS now.

Are MD Arrays even possible in LS?

evenflcw
12-29-2003, 03:27 AM
I'm not really sure about the terminology (kinda newbie-ish myself), but with multidimensional arrays I meant something like BlaBlaha[1][1] which I believe are possible and those seem multidimensional enough for me. :)

While-loop's the fastest! I'll have to make more use of them then.

The speed-problems I was talking about have mostly to do when I have to perform alot of operations on polygons/points one after the other. Otherwise it's fine.

wiffzack
12-29-2003, 03:49 AM
hehe, i never used md arrays yet. btw i dont even know how to initialize them?

But in most cases i dont need them. I think they slow down a script too.

Ive tested for against while but they seem to be exactly the same. ( i run 2000000 loops and tested the seconds. but i am not shure this is usefull info)

faulknermano
12-30-2003, 08:40 AM
Not considering the use or time it takes to create them, will large amounts of data make scripts run any slower? (Housed in arrays for example; and I'm not talking about ridiculus amounts that would max out the RAM.)

this is hard to say unless you measure the time. frankly i havent the time to do such a speed measurement.


Is it faster to use several onedimensional arrays instead of a larger multidimensional one?

this has nothing to do with speed: but i only use multidim array when i need to, when my data needs to be stored and arranged like so. in nonlinearmorphdm, i used multidims the whole way, storing each vmap point's endormorph vectors. it could not have been done otherwise. i would like to hazard a guess that if lscript's memory management is like C, then i think that multidim or not, they still use the the same memory addresses. in other words: no, there's no difference. it's all about the data, not the "containers."


Are all loops (for(), foreach(), while()) equally fast and can one just choose depending on what type suits the situation best or should one make an extra effort to try and use a particular one?

again, not about speed: but using for() will sometimes 'read' better than while(), while, at time, the opposite is true. when i mean "read" i mean it is easier to code your stuff. for example, when needing to iterate through an array, a for() is more convenient because while() needs you to iterate the counter variable explicitly inside the while() block, making the code look messier than it would otherwise be if you had used for().



Is it necessary to nil all variables and arrays at the end of an lscript or does the lscript engine do this by itself?

lscript trashes the values at the end. you dont have to do it yourself.

evenflcw
12-30-2003, 09:48 AM
Big thanks to the both of you for clearing all that up! I guess I need not worry so much then :)