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

 
amrali #:
Is your pc is out of memory ?!

Edit:
The code will be optimized into the processor registers not in cache.

Yup, it doesnt make any difference anymore. - or at least its not measurable.

It was out of curiosity.

EDIT: In a virtual machine it actually shows a slight tendency to perform minimally better, when cache-line and memory optimized. - Though, this test is very synthetic. And its just a tendency... not a guarantee, so could be OS scheduler related, or whatever is between the code and the CPU...

BTW: I removed the commented lines from the function, which gave it a bit of an edge.... - Why ever this is the case, but since we are in the picosecond area, its not even possible to draw any conclusions from that.
 

I will remove this function from the benchmark as it is not reliable:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
// https://www.mql5.com/ru/forum/170952/page247#comment_52620994
// true - оптимизация компилятора включена, false - выключена.
bool IsOptimizationCompiler( void )
{
  static ulong PrevValue = INT_MAX;

  if (PrevValue == INT_MAX)
  {
    const ulong StartTime = GetMicrosecondCount();

    for (int i = 0; i < 1e5; i++)
      const double j = MathSin(0);

    PrevValue = GetMicrosecondCount() - StartTime;
  }

  return(PrevValue < 5);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart() {
   Print("\nCompiler Version: " + (string)__MQLBUILD__ + " " + __CPU_ARCHITECTURE__ +
         ", optimization - " + (string)IsOptimizationCompiler());
}

I compiled this on my machine as X64 regular, no optimizations, then I got this result

2024.11.30 19:20:17.616 IsOptimizationCompiler (EURUSD,H1)      
2024.11.30 19:20:17.616 IsOptimizationCompiler (EURUSD,H1)      Compiler Version: 4647 X64 Regular, optimization - true
 

A small fix (casting datetime to uint), but increasing performance by two times:

bool TimeToJulian(datetime time, MqlDateTime& dt_struct)
  {
   uint t = (uint)time;  // cast datetime to uint for speed-up

Updated benchmarks v1.10:

Compiler Version: 4620 X64 Regular
13th Gen Intel Core i7-13700KF, AVX2 + FMA3
1970.01.01 00:03:02 - 2097.11.29 23:55:39, random datetimes[]
 4.04 ns, checksum = 161301871646119   // TimeToStruct2100
 3.91 ns, checksum = 161301871646119   // TimeToStructFast
 4.10 ns, checksum = 161301871646119   // TimeToCalendar
 4.62 ns, checksum = 161301871646119   // TimeToJulian
18.77 ns, checksum = 161301871646119  /// MQL's TimeToStruct()
 
amrali #:

I will remove this function from the benchmark as it is not reliable:

I compiled this on my machine as X64 regular, no optimizations, then I got this result

Yes, this function is designed for a certain level of CPU power.

We would need an approach where we can reliably tell, this code has been removed by the optimizer.

I was thinking about some more reliable approach, but am not certain what could be used.
 
Dominik Egert #:

We need an approach where we can reliably say that this code was removed by the optimiser.

I was thinking of some more reliable approach, but I'm not sure if it's possible to use it.

The ratio of runtimes of code that definitely won't be deleted and code that might be deleted will go?

 
JRandomTrader #:

The ratio of runtimes of code that will definitely not be deleted to code that might be deleted will go?

I wonder what google translator will turn this phrase into (((

 

Forum on trading, automated trading systems and testing trading strategies

Features of mql5 language, subtleties and techniques of work

amrali, 2024.11.30 17:21

I will remove this feature from the benchmark as it is unreliable:

2024.11.30 19:20:17.616 IsOptimizationCompiler (EURUSD,H1)      
2024.11.30 19:20:17.616 IsOptimizationCompiler (EURUSD,H1)      Compiler Version: 4647 X64 Regular, optimization - true


Forum on trading, automated trading systems and testing trading strategies

New version of MetaTrader 5 build 4410: improvements in performance

fxsaber, 2024.08.31 15:28

Compiler: b4410 vs b4512.
.


This code produces different results when optimisation is disabled.

void OnStart()
{
  Print((string)TerminalInfoInteger(TERMINAL_BUILD) + " - " +
        (string)IsOptimizationCompiler()); // https://www.mql5.com/ru/forum/170952/page247#comment_52620994
}
4410 - false
4512 - true

I.e. some optimisation is enabled in 4512 compared to b4410.


Debug (F5):

Compiler Version: 4709 AVX, optimization - false
 
amrali #:

A small fix (converting datetime to uint), but doubles performance:

If done for TimeToCalendar, it will speed up there too.

   uint t2 = (uint)t;
   int HH  = (int)((t2 / 3600) % 24)             ;
   int MM  = (int)((t2 / 60) % 60)               ;
   int SS  = (int)(t2 % 60)                      ;
 
fxsaber #:


I.e. some optimisation is enabled in 4512 compared to b4410.

it is unreliable since v.4512, So, why do you keep using it?
 
amrali #:
It has been unreliable since version 4512, so why do you keep using it?

This function indicates the presence/absence of a particular compiler optimisation, not the presence/absence of the compiler GUI flag of the same name.