ID:154062
 
Im not knowledgeable as to how exactly it works, but which of the following would be more effecient:
mob/proc/Regain() stat++ spawn(regain_time) Regain()
or
ticker Update() for(var/mob/M) M.stat++ spawn(regain_time) Update()
Keeping in mind that there will be 500+ mobs eventually.

Thanks,
Alathon\\
Do profiling and try to find out that way.
The last would be more efficient, but the first is more object-oriented. You can try a compromise to get the qualities of both:

<code> mob/proc/Regain() stat++ ticker Update() for(var/mob/M) M.Regain() spawn(regain_time) Update() </code>
In response to Spuzzum
Spuzzum wrote:
The last would be more efficient, but the first is more object-oriented. You can try a compromise to get the qualities of both:

<code> > mob/proc/Regain() > stat++ > > ticker > Update() > for(var/mob/M) M.Regain() > spawn(regain_time) Update() > </code>

Since the function is one line of code I don't think it would be a good idea. The overhead of the function call would make the loop significantly slower. But if different mobs have different Regains then use a function since in that case it would be much more readable as a set of seperate function than a switch statement or a line of ifs.
In response to Theodis
Since the function is one line of code I don't think it would be a good idea. The overhead of the function call would make the loop significantly slower. But if different mobs have different Regains then use a function since in that case it would be much more readable as a set of seperate function than a switch statement or a line of ifs.

Yeah, I know; I was operating under the assumption that Alathon would have multiple lines of code in the Regain() proc, and would want to change it quickly at some point in the future.

Besides, in BYOND, I don't think that function calls are a whole lot laggier; it's just a single jump -- rather than adding one to the current point of execution, it adds one, then sets the point of execution somewhere else. It's a single-threaded system, after all.

If BYOND could support hundreds of thousands of objects, then it would probably be a concern. But as of now, with a 65K limit of objects, that's not too problematic for a mid-level processor with several hundred million hertz. =)
In response to Spuzzum
Besides, in BYOND, I don't think that function calls are a whole lot laggier; it's just a single jump -- rather than adding one to the current point of execution, it adds one, then sets the point of execution somewhere else. It's a single-threaded system, after all.

Since BYOND supports recursion I'm sure it has to dump the current state of the function on the stack as well as the parameters when it calls a function. Then when returning it has to pop that back off the stack. For one line of code this is a lot of overhead.