View previous topic :: View next topic |
Author |
Message |
dguntner
Joined: 31 Dec 2004 Posts: 116
|
Posted: Wed Aug 24, 2005 6:33 Post subject: |
|
|
You're probably right, Prim. And yea, that's the solution I use on my server so that I can store needed information about a departing player in the database. Works well.
--Dave |
|
Back to top |
|
|
Lanthar D'Alton
Joined: 10 Feb 2005 Posts: 100
|
Posted: Thu Sep 08, 2005 1:41 Post subject: A thread you should probably read |
|
|
http://www.nwnx.org/phpBB2/viewtopic.php?t=155&postdays=0&postorder=asc&start=0
That discusses the discovery that nwscript switch statements are equivalent to giant if/else statements.
of particular relevance to this thread:
Lanthar D'Alton wrote: | Here are a few more things about efficiency for those not so keyed to it...
two scripts:
strcompare
Code: |
void main()
{
int i=0;
for(i=0; i<8191; i++)
check(i);
SendMessageToPC(GetLastUsedBy(), "strcompare done");
}
void check(int variable)
{
if("123"=="abc")
1;
}
|
The code I used for ints (main was same as above):
intcompare
Code: |
void check(int variable)
{
if(1==variable)
1;
}
|
That strcompare one will run precisely 1 too many commands for nwn... causing a TMI error, AND sending the message anyway... oddly the intcompare one also TMIs but never sent the message. Both scripts do complete if I change the for(...) to only go to 8190.
Anyway, that's just something I always wondered... how many instructions are too many. I'm not surprised that it comes rather close to a power of 2 in the loop (8192)...
As for the importance of running this test... well, it gave me efficiency results that are very good to demonstrate why using ints is better than using FindSubString or any of that.
Code: |
intcompare : 0.007793 per call
strcompare : 0.037566 per call
|
So... Comparing 3 letters to 3 other letters eats ... 4.82 times the cpu as comparing 2 integers.
Anyway, that's just a bit of example to explain why we programmers don't like to run string comparisons unless we absolutely have to.
-Lanthar |
Thus, it can make that script run 8190 times through it's loop without dying.
Naturally there's some overhead to the function call and some other stuff. |
|
Back to top |
|
|
dguntner
Joined: 31 Dec 2004 Posts: 116
|
Posted: Fri Sep 09, 2005 4:03 Post subject: |
|
|
I remember that discussion. I also remember posing the question asking if you had tried compiling the module with the PRC stand-alond script compiler to see if it treated switch statements differently than the default Bioware compiler.
Never did get an answer from you on that.
--Dave |
|
Back to top |
|
|
|