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

 
Vladimir Simakov #:

But how many clock cycles, what instruction takes - dig it yourself, who is interested))))

IMHO, in practical terms, it is absolutely unimportant.

I got rid of the other.

Forum on trading, automated trading systems and testing trading strategies.

Libraries: Virtual

fxsaber, 2025.01.08 16:06

use changes the internal hidden architecture of the library, bypassing the corresponding slowing down features of MQL5/RAM. Makes sense to use if you need speed of calculations - Tester.

Free of charge increases performance by tens of per cent, at least.

Briefly, what gave such a gain on a practical task.

  • Refusal to work with pointers - no time is wasted on checking their validity.
  • Refusal to copy simple structures (A = B). For example, to access an element of an array of structures only through an index, not by copying the element into a separate structure (variable).
I had to go to a lot of trouble, but the result is great.
 

I pass the Close[] array to the function.

double Close[];
function(Close);
void function(double &array[]){}

Is it possible to find out the name of this array inside this function through the code, instead of writing "Close[]" in the print?

[Deleted]  
Andrei Iakovlev #:

I think not. The function just takes an array as an argument. You can create structures with two fields. One contains the array itself, the other its name, and pass this structure to the function. But it is the same as passing the array name as a separate argument.

 
Andrei Iakovlev #:

Some variable has a value of -1.

Which check will be executed faster to check this value: < 0 or == -1?

Technically speaking, equal evaluation always processes the whole data (32 or 64 Bit), while an unequal, smaller or greater will stop at the moment this evaluation is deterministic. But the gains are so small, CPUs nowadays dont give you back this speedup due to the way the pipelining is implemented. Not sure how this would play out if it were possible to saturate the pipeline with only one type of comparison. Maybe you would be able to measure actually an advantage over the other operator.

Practically, you can actually ignore it for integers. Its a bit different for doubles, as you usually wouldn't compare them to be equal.

A significant and measurable difference can be found, if you avoid division and try to replace them with multiplication. Also if you are able to avoid the modulo operator, which is also "just" a division.

The cost of a division is around 25 to 30 cycles, while a multiplication is around 10 cycles. (Something along these lines, varies with architecture) its round about 1:3 in cost relation.
 
Andrei Iakovlev #:

Some variable has a value of -1.

Which check will be executed faster to check this value: < 0 or == -1?

It is better to replace a==b with (a-b)==0 , it is better.

 
Putnik #:
Looks like the auto translator's glitchy.

No, everything is fine -

 

OK, thanks.

I logged in from another computer, only one error.


 
Putnik #:

It is better to replace a==b with (a-b)==0 , it is better.

Why? This is operationally more expensive than a direct comparison.

Please explain.
 
Dominik Egert #:
Why? It's operationally more expensive than a direct comparison.

Please explain.

Because direct comparison of real numbers often leads to wrong results. And because of this, some people thoughtlessly apply this method wherever necessary and wherever not necessary.

And in fact, the original variant, if it differs, is very insignificant.

 
Dominik Egert #:
Why? It's operationally more expensive than a direct comparison.

Please explain.

On the premise that operationally it will be cheaper. That's what my high school computer teacher said.

I can't say for sure, so I won't argue.