Which operation / command executes fatser?

Is it faster to increment a variable by using:
nVar = nVar + 1;

Or do both operations take the same amount of compute time?

EDIT: typo

The first one should be faster, but use what you’re comfortable with - modern PC compilers would recognize the + 1 and optimize them both to an increment instruction, I have a feeling this doesn’t happen in PAC control though.

Edit: Increment is about 15% faster on SoftPAC.

I have to ask: Why do you ask? Are you just curious?

Because… if you’re trying to speed things up, there are other ways to address this concern. For example, in PAC Control under the Configure menu, do you have “Full Debug” or “Minimal Debug” selected?

I’d agree with @philip, if one makes more sense to you, perhaps is faster to type, use that one since the difference in speed of execution is not going to be relevant in the Grand scheme of things.

1 Like

Just curious! This is the first time I’ve seen a dedicated command for incrementing or decrementing, so I didn’t know if there was any advantage to it over explicit assignment…that and the usual things like nVar += 1 or nVar -= 1 don’t seem to work.

The += operator is only for string appending in Optoscript. It would be nice to have +=, -= for numeric types. Also, be aware that IncrementVariable doesn’t work on numeric tables - another puzzling one.

Good to know - thanks for the heads up!