[quote]Lightfoot8 wrote...
[quote]Zarathustra217 wrote...
Sorry for the off topic, but I find this very much interesting. I figure this also entails that if you have to look for a handful spell effects on a creature, it is faster to use GetHasSpellEffect several times than to loop through each effect on the creature and check for the spell ID of that effect. Normally, I would expect latter solution to be most effective (one search vs. multiple) but given that the GetHasSpellEffect is an internal function, it would be far faster than the scripted loop.
Thoughts?
[/quote]
Yep, That is what is being said.
[quote]Failed.Bard wrote...
A well written homebrew function compiled with one of the better compilers (like is integrated into Virusman's toolset extender) will be faster than the equivalent likely 95% of the time. Every single replacement function I've written and compared to the bioware default has been faster, even if only by a few percent over thousands of cycles.
Likely this deserves its own topic though, so people could get more in depth into replacement function comparisons.
[/quote]
Yes, Home brew vs Home brew can be compiled better using a better compiler.
Try and rewrite an internal function with nwscript, something like GetItemPossessedBy, and see if you get any gain. [/quote]
I'd realized after I made my post that most of the functions I've replaced are ones that were in includes, which weren't the sort that Lightfoot8 had been referring to in his original post on it anyways.
Regardless, since I'm always curious about this sort of thing, I did a bit of testing on it, using everyone's favourite inefficient function: GetNearestObjectByTag.
This one is fairly cycle heavy. I'd originally planned to run the tests at 1000 loops of each script variant, but it was giving TMI errors already after 23 loops using 100 equally tagged placeables. I ran it at loops of 20 instead.
The main command function:
[quote]
void main()
{
object oPC = GetPlaceableLastClickedBy();
int i;
for (i; i< 20; i++)
{
ExecuteScript("test_gnobt_bio", oPC);
ExecuteScript("test_gnobt_1", oPC);
ExecuteScript("test_gnobt_2", oPC);
}
}[/quote]
"test_gnobt_bio"
[quote]
void main()
{
object oTest = GetNearestObjectByTag ("x2_easy_Barrel");
}[/quote]
"test_gnobt_1"
[quote]
object GetNearestObjectByTag_1 (string sTag, object oSource = OBJECT_SELF)
{
object oNearest = OBJECT_INVALID;
int i;
float fNearest = 3000.0, fTest;
object oArea = GetArea (oSource);
object oTest = GetObjectByTag (sTag);
while (GetIsObjectValid (oTest))
{
oTest = GetObjectByTag (sTag, i);
if (GetArea (oTest) == oArea)
{
fTest = GetDistanceBetween (oSource, oTest);
if (fTest < fNearest)
{
oNearest = oTest;
fNearest = fTest;
}
}
oTest = GetObjectByTag (sTag, ++i);
}
return oNearest;
}
void main()
{
object oTest = GetNearestObjectByTag_1 ("x2_easy_Barrel");
}[/quote]
"test_gnobt_2"
[quote]
object GetNearestObjectByTag_2 (string sTag, object oSource = OBJECT_SELF)
{
object oTest, oNearest = OBJECT_INVALID;
float fNearest = 3000.0, fTest;
object oArea = GetArea (oSource);
oTest = GetFirstObjectInArea (oArea);
while (GetIsObjectValid(oTest))
{
if (GetTag (oTest) == sTag)
{
fTest = GetDistanceBetween (oSource, oTest);
if (fTest < fNearest)
{
oNearest = oTest;
fNearest = fTest;
}
}
oTest = GetNextObjectInArea (oArea);
}
return oNearest;
}
void main()
{
object oTest = GetNearestObjectByTag_2 ("x2_easy_Barrel");
}[quote]
The results were interesting, not in that the Bioware one was faster, I expected that with the higher placeable count searches, but in how wide a range the script profiler was giving doing the exact same tests when it was only 10 placeables with that tag to search through.
Here's the numbers I got:
[quote]
100 equally tagged placeables:
test_gnobt_bio 200 - 140
test_gnobt_1 200 - 173
test_gnobt_2 200 - 219
50 equally tagged placeables:
test_gnobt_bio 200 - 77
test_gnobt_1 200 - 93
test_gnobt_2 200 - 141
20 equally tagged placeables:
test_gnobt_bio 200 - 46
test_gnobt_1 200 - 79
test_gnobt_2 200 - 94
10 equally tagged placeables:
test_gnobt_bio 200 - 92
test_gnobt_1 200 - 31
test_gnobt_2 200 - 62
test_gnobt_bio 200 - 32
test_gnobt_1 200 - 63
test_gnobt_2 200 - 61
test_gnobt_bio 200 - 63
test_gnobt_1 200 - 63
test_gnobt_2 200 - 63
test_gnobt_bio 200 - 62
test_gnobt_1 200 - 15
test_gnobt_2 200 - 94
test_gnobt_bio 200 - 64
test_gnobt_1 200 - 47
test_gnobt_2 200 - 91
[/quote]
This was in a small hakless testing module as well, and it seemed like overhead had a bigger effect on script execution time than the scripts themselves did.
In the example with these scripts, I expect areas with huge numbers of placeables, when searching them for 1 or 2 like tagged objects, the homebrew would likely be faster, but in most normal circumstances not.
I think I'll take a look through some more of the default functions to see if there are any others that might be worth testing against replacement functions.
Certainly anything in an include file can be done more efficiently, but I'm curious if there are some of the internal ones that could be as well.
edit: fixed an error I noticed in the test scripts posted. Forgot to assign fTest, so the first object found always detected as the nearest. It wouldn't have affected the execution speed comparison tests though.
Modifié par Failed.Bard, 21 juillet 2012 - 03:12 .





Retour en haut







