View Single Post
  #36  
Old 09-14-2009, 06:56 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by salesman View Post
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.0temp.temp.maxtemp.i++) {
    
db_test.variable temp.i;
  }
  echo(
"dNPC" SPC timevar2 temp.init);
  
// findNPC
  
temp.init timevar2;
  for (
temp.0temp.temp.maxtemp.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.0temp.temp.maxtemp.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.
__________________
Quote:
Reply With Quote