Features of the mql5 language, subtleties and tricks - page 288

 
Roman #:

If we proceed from the task " how to make equal faster"...
Then we should reduce possible conventions and operations.
In my opinion switch will be the fastest at the level of assembly registers.

And the remainder from division is an expensive operation.
That's what Renat wrote.

Note that I have not said a word about the usefulness of your variant, use whatever you want. After all, I am not imposing anything on anyone.

You could talk about execution speeds on Pentium computers or earlier...

 
Alexey Viktorov #:

Note, I have not said a word about the usefulness of your option, use whatever you want. After all, I am not imposing anything on anyone.

You could talk about execution speeds on Pentium computers or earlier...

It seems we share our view, without pretensions to uniqueness.
And imposition is out of the question.
Strange and not clear your position, immediately into the rack ))

 
Roman #:

In my opinion switch, will be the fastest at the assembly register level.

I assume that the XOR variant is faster.

 
fxsaber #:

I assume the XOR variant is faster.

Hm...
Indeed, you get one operation, no branching.
switch is redundant.

int x=0;
Print(x ^= 1);
Print(x ^= 1);
 
Roman #:

Hm...
Indeed, you get one operation, no branching.
switch is redundant.

but switch is more correct. Int toggle_value(int &x) { return x=x^1; } is beaten for optimisation. Because the optimisation is miserable, and when 'x' has the 3rd allowed value (it will be int, too), a hard-to-find glitch will appear in the project.

so either switch or x must be bool.

 
Micro-optimization such as × ^= 1 are useful only if they lie in a "hot path" of your program, where the code will be executed extensively or very frequently. 

But, if the code containing this expression, say for example is 1% of the total execution time (i.e., a "cold spot"), then even a 100x speed-up of this expression is not useful at all, because the total execution time is still 99.01% (0.99 main path + 1/100) of the original non-optimized code.

The profiler is useful to detect these bottle-necks in your program.

 
When writing an indicator in mt5 does not correctly count arrays, both dynamic and static. The cycle with the correct sizes gives an error if you assign values to them. What is this nonsense, how long has the problem been like this?
 
Papa Hoth writing an indicator in mt5 does not correctly count arrays, both dynamic and static. The cycle with the correct sizes gives an error if you assign values to them. What is this nonsense, how long has it been such a problem?

Example?

 
Papa Hoth writing an indicator in mt5 does not correctly count arrays, both dynamic and static. The cycle with the correct sizes gives an error if you assign values to them. What is this nonsense, how long has it been such a problem?
Where is the peculiarity?
 
JRandomTrader #:

Example?

int Arr [4]
(For int i=0;i<=Arrsize(arr);i++)
{
Arr[i]=i;
}
The error is a wrong array measurement.
I don't have a PC at hand now, so I write it this way, but the essence of the code is clear. There are no errors in the code, as it works properly in the council.