MZ Functions that require more processing time

Forgive me for being a noob. But as I become more conscious about optimization, I want to know what kind of function demands more power/time from another.

For example:

Code:
$gameActors.actor(actorID).addState(stateID);

$gameActors.actor(actorID).setName(string);

$gameParty.gainItem($dataItems[id], amount);

$gameVariables.setValue(index, value);

subject.forceAction(skillID,target);

How will I arrange this five lines of code from smallest to highest demand in processing time. And how did you arrange it?
unfortunately programming doesn't work that way. most of your examples have only the smallest processing steps and in the other cases the processing steps go entirely outside the scope.

let's take the last command as example of that.
force action basically tells the engine to execute a skill with the given data. But that skill is NOT executed in the context of the force action function.

first, different skills have different needs on processing. that means even if it were executed in context it would require different answers.
second, part of any skill executions are waits - the animation for example is usually executed in an update loop where the screen is updated, within a loop that does a lot of other things at the same time while waiting literally uncountable frames between the updates of "show next picture of the animation sequence".

and all other examples are basically quick data assignments that are handled too fast to make the difference count for any optimization.

on modern computers and games the bulk of lag comes from other sources than handling single functions. it's loops of excessive executed functions that create lag.
About a previous RPG Maker i read in the past that it was faster to
use Move Picture 100 Times to Make Menu Pictures invisible and visible instead of using
Erase/Show Picture when Menu is opened. (RM2K3?)
But that was realy long ago and cant recall the whole context again... i believe it doesnt matter nowadays.

For Eventcode Optimization:

If statements (Conditions) use the least amount of Performance reserves, so they dont matter.
Simple Switch and Variable Control, a bit more but nearly the same as conditions.

You can have hundrets if not thousands of those in a Parallel Event running all the Time every Frame without Problems. Those are ment to be used and are ment to build your Game Logic.

If you than start to execute other commands all the Time or more often than needed,
than you start wasting your performance reserves or you make your Game unplayable on Weak Systems. Atleast it appears to me like that, iam just a casual user myself.

Where it could matter:
If you have a complicated on map battlesystem hit detection with 1000+? maybe 5000+
Advanced Calculations with Math Hypothenusis, sin, cos sin, angle and more all together...
than maybe using .abs math function could be better than Hypothenusis and make a difference in rpg maker.
But those cases are rare and Limited. I also cant provide Numbers, its just old stuff (half knowledge)
i recall having read years ago about this Topic.

Dont create more Parallel Processes than needed. That can result in Problems or seems to drain also Performance reserves, atleast i think i observed that in older rpg makers. but could be wrong about that, since i sometimes missinterpreted stuff in the past, so correct me if iam wrong.
Keeping in mind what Andar said, you can see how much time a piece of code is taking to execute in YOUR computer. You can do that using console.time . Let me give you an example
JavaScript:
console.time('name of time 1');
// Some javascript code
console.timeEnd('name of time 1');
and this would output in the console something like
Code:
name of time 1: 0.260009765625ms

Again keep what Andar said as you test that this, and also keep in mind how javascript works itself, while it is a single threaded language (under normal circumstances), it uses a call stack system so it can pause a code execution to run another (though for simple code this shouldn't be important).

I can add that IO operations would be most of the time the most resource intensive.
I can add that IO operations would be most of the time the most resource intensive.
IO ??? What do you mean with that? I dont understand.
Forgive me for being a noob. But as I become more conscious about optimization, I want to know what kind of function demands more power/time from another.

For example:

Code:
$gameActors.actor(actorID).addState(stateID);

$gameActors.actor(actorID).setName(string);

$gameParty.gainItem($dataItems[id], amount);

$gameVariables.setValue(index, value);

subject.forceAction(skillID,target);

How will I arrange this five lines of code from smallest to highest demand in processing time. And how did you arrange it?

In order to make a guess about processing time, you'd have to go look at the source code and see what each function does. But like Andar said, the potential performance impact of a function goes beyond the processing time of the function itself. You have to bare in mind that each of those functions will ultimately trigger other changes within the game, which happen outside of the scope of the function itself.

For example, the function to add a state will basically just push a value onto an array, and then it will call a refresh. After that point, the function's processing time is done, yet the changes that it triggered in the engine aren't done. For example, next update, the engine might have to render a graphic onto the screen to indicate that change of state. It might have to do calculations and whatnot involving the effects that were added by the state. These things happen outside of the context of the addState function, yet they will still ultimately be triggered by the addState function. Unfortunately, it can be hard to measure stuff like this.

But really, I think this is kinda the wrong question to be asking anyway. Like, what's the point in comparing the performance of different functions that serve completely different purposes? I don't see how that will really help you optimize anything. It's not like you're going to be writing some code, and suddenly think: "I'd like the party to gain an item, but since gainItem is slower than setName, I think I'll just change an actor's name instead." Do you understand what I mean? They aren't exactly two different solutions to the same problem, so there is no optimization potential there. If you want to set a name, then use setName, and if you want to gain an item, then use gainItem. There is no reasonable situation where knowing the difference between the execution time of those two functions will ever be valuable to you.

IO ??? What do you mean with that? I dont understand.

Input/Output

Original thread: https://forums.rpgmakerweb.com/threads/functions-that-require-more-processing-time.150198/