So, I made some test scripts with 100 possibilities (100 if/else, 100 cases, 100 local ints stored). I tested the local calls with variable names of sizes 2, 8, 16, 32 and 64. Each local variable script had its own object with 100 pieces of data stored on it, and one script stored and retrieved data using GetModule (which used length 2 variable names as well).
My theory was the local variable calls of lengths 2 and 8 would be the fastest, followed by the case, then then the other local calls from smallest to largest, then the if/else. String comparisons are anything but effecient, but I thought modern CISC processors would have intructions specifically for comparing strings. Also, I thought the much smaller size of a single GetLocal call vs. a huge if/else or switch would mean much more code would reside on the processor's cache.
Here are the results without any scripts cached in module properties:
Code: Select all
test_2molocal_100 290 msec 1001 calls
test_2local_100 215 msec 1001 calls
test_8local_100 229 msec 1001 calls
test_16local_100 248 msec 1001 calls
test_32local_100 290 msec 1001 calls
test_64local_100 364 msec 1001 calls
test_switch_100 995 msec 1001 calls
test_ifelse_100 1110 msec 1001 calls
Code: Select all
test_2molocal_100 282 msec 1001 calls
test_2local_100 212 msec 1001 calls
test_8local_100 227 msec 1001 calls
test_16local_100 247 msec 1001 calls
test_32local_100 281 msec 1001 calls
test_64local_100 355 msec 1001 calls
test_switch_100 973 msec 1001 calls
test_ifelse_100 1089 msec 1001 calls
Also, we can see how GetModule() slowed things down a bit, as the only difference between test_molocal_100 and test_local_100 is a global object is substituted for GetModule().
Well, I was right about the lesser local variables being fast at least. I didn't expect the case and if/else to get their ass kicked quite as badly as they did...
So, I think I've reached a few conclusions:
-NWscript doesn't compile switch statements well at all.
-Local variables are fast.
-The length of local variable names isn't important unless your doing an obscene number of calls.
-NWscript is not as slow as I thought. After 8008 calls .1 seconds apart (100 seconds), it only used up 3.646 seconds of system time.