Quote:
Originally Posted by salesman
Wouldn't findNPC() be less efficient because you're calling a function to get the object instead of just referencing it by name? Especially when people use findNPC(npcname) over and over again instead of assigning the npc to some variable.
I have no idea, but it just seems like it would be.
|
I wondered this as well so..
PHP Code:
function benchmark() {
// Iterations
temp.max = 100000;
// Direct
temp.init = timevar2;
for (temp.i = 0; temp.i < temp.max; temp.i++) {
db_test.variable = temp.i;
}
echo("dNPC" SPC timevar2 - temp.init);
// findNPC
temp.init = timevar2;
for (temp.i = 0; temp.i < temp.max; temp.i++) {
findnpc("db_test").variable = temp.i;
}
echo("fNPC" SPC timevar2 - temp.init);
// Variable findNPC
temp.init = timevar2;
temp.db = findnpc("db_test");
for (temp.i = 0; temp.i < temp.max; temp.i++) {
temp.db.variable = temp.i;
}
echo("vNPC" SPC timevar2 - temp.init);
}
Results:
NPC Code:
JerretNPC: benchmark()
dNPC 0.069311141 seconds
fNPC 0.10556817 seconds
vNPC 0.061683177 seconds
Specifying findNPC every time appears to take twice as long (in my benchmark anyway) compared to variable and direct methods.