First test is complete. I may not have to do any others.
This used the bioware profiler - first time I've done profiling with it, rather than NWNX (also the first time since 1.69).
This was done on HG, with the normal placeable counts, etc, in an actual-practice situation. We retrieve an object to use as an effect creator for diseases that inflict vulnerability. Nowadays, we set effect ids using nwnx_structs, but we didn't convert everything to that. Anyway, here's the actual code in the module for it. As you can see, we use the waypoint/tag technique:
void DoDiseaseVuln (object oDiseased) {
object oArea = GetArea(oDiseased);
if (!GetIsObjectValid(oArea)) {
DelayCommand(6.0, DoDiseaseVuln(oDiseased));
return;
}
int nAmount = GetLocalInt(oDiseased, "DiseaseVuln");
if (!nAmount)
return;
if (GetIsDead(oDiseased)) {
DeleteLocalInt(oDiseased, "DiseaseVuln");
return;
}
object oEffectWay = GetWaypointByTag("effectsareawaypo");
object oDiseaseControl = GetNearestObjectByTag("disease_vuln", oEffectWay);
effect eTest = GetFirstEffect(oDiseased);
int nApplied = FALSE;
while (GetIsEffectValid(eTest)) {
if (GetEffectCreator(eTest) == oDiseaseControl)
nApplied = TRUE;
eTest = GetNextEffect(oDiseased);
}
if (!nApplied) {
AssignCommand(oDiseaseControl, ApplyDiseaseVuln(oDiseased, nAmount));
}
DelayCommand(6.0, DoDiseaseVuln(oDiseased));
}
That waypoint, effectsareawaypo, is in a small, 4x4 area, with very few objects - just a waypoint and 7 places - it was designed specifically to keep GNObT streamlined.
I placed 3 objects in our test area in the mod, each with a different heartbeat script:
test_gnobt
void main()
{
object oDiseaseControl;
int nX;
for (nX = 0; nX < 1000; nX++)
oDiseaseControl = GetNearestObjectByTag("disease_vuln", GetWaypointByTag("effectsareawaypo"));
}
test_gobt
void main()
{
object oDiseaseControl;
int nX;
for (nX = 0; nX < 1000; nX++)
oDiseaseControl = GetObjectByTag("disease_vuln");
}
test_glo
void main()
{
object oDiseaseControl;
int nX;
for (nX = 0; nX < 1000; nX++)
oDiseaseControl = GetLocalObject(GetModule(),"disease_vuln");//set on modload
}
Here are the results of the profiling run:
test_gnobt runs 348 total time 4900
test_gobt runs 348 total time 685
test_glo runs 348 total time 1395
So, according to this test, at least, GetObjectByTag outperforms even GetLocalObject, even on a huge mod like HG which probably has upwards of 70,000 objects in play (wild-ass guess based on 50k place count and 566 areas). We don't have a lot of vars on the mod, either - under 20, if I had to guess. Note that I used GetModule() each time, rather than assigning a var - again, because that's likely what you would be doing in practice, unless you happened to be working on a script where OBJECT_SELF was the mod.
I'm a little concerned at the number of runs - I think load may have played a role in the numbers, perhaps distorting them, since I let this run quite a while, and there should've been more runs. Still, the numbers speak for themselves. Looks like the common wisdom was wrong again - props to Mavrixio for pointing this out.
'>
I'll probably do some additional runs this evening to see whether all objects in an area get checked by GNObT before it picks one, but that's sort of irrelevant, now. All you need is a good prefixing system to ensure unique tags - with that, GObT is definitely the way to go. I may also compre GObT to GetWaypointByTag, to see if GWbT has similar optimization.
Funky
Modifié par FunkySwerve, 22 août 2011 - 04:47 .