Ajuda com o OOP - página 6

 
Não se esqueça de remover a estática
 
fxsaber #:

Eu não vejo o problema.

Você tem que remover a "estática" antes de "union u_Data_t".

static union u_Data_t
 
PapaYozh #:

Portanto, você tem que remover a "estática" antes de "union u_Data_t".

Release: 12487.905
Debug: 9357.236

b3062. De fato, a divergência está na direção errada.

 

Os números são assim, após o teste anterior o código foi ligeiramente otimizado:

Sem depuração e liberação estática, por último com liberação estática

174.326
13513.946
46.408
 
fxsaber #:

b3062. De fato, a discrepância está na direção errada.

Portanto, você tem uma pequena diferença

 
Aliaksandr Hryshyn #:

Portanto, você tem uma pequena diferença

Escreva no ramo da última construção com o código completo e os resultados. Tal construção não vai passar pelos desenvolvedores.

 
fxsaber #:

A resposta é de preferência imediata. Nem sempre há tempo para a experimentação.

#define               ARRAY_SIZE           int(100)
#include <Arrays\ArrayObj.mqh>
class Test : public CObject
{
public:
   int               a;
   double            b;
   datetime          c;
   Test(){};
   Test(int ai){this.a = ai;}
};
int COUNT = 1000000;
 
void OnStart()
{
   FooV3();
}

void FooV1()
{
   long t = GetMicrosecondCount();
   Test array[];
   ArrayResize(array, COUNT);
   for(int i = 0; i < COUNT; i++)
      array[i] = Test(MathRand());
   long delta = GetMicrosecondCount() - t;
   printf(delta);
}
void FooV2()
{
   long t = GetMicrosecondCount();
   Test* array[];
   ArrayResize(array, COUNT);
   for(int i = 0; i < COUNT; i++)
      array[i] = new Test(MathRand());
   long delta = GetMicrosecondCount() - t;
   printf(delta);
}
void FooV3()
{
   long t = GetMicrosecondCount();
   Test* array[];
   ArrayResize(array, COUNT);
   for(int i = 0; i < COUNT; i++)
      array[i] = new Test(MathRand());
   for(int i = 0; i < COUNT; i++)
      delete (array[i]);
   long delta = GetMicrosecondCount() - t;
   printf(delta);
}

Resumindo: é mais rápido sem indicações. Tenho 1,2 seg sem ponteiros (V1), 1,4 com ponteiros (V2). 1.6 - com ponteiros e remoção (V3).

 
Os objetos criados com novas chamadas e métodos são mais lentos. caso você não soubesse)))))
 
Vasiliy Sokolov #:

Resumindo: é mais rápido sem indicações. Tenho 1,2 seg sem ponteiros (V1), 1,4 com ponteiros (V2). 1.6 - com ponteiros e remoção (V3).

A comparação é incorreta porque não leva em conta o tempo que leva para apagar objetos automaticamente.

Modificado.

#include <Arrays\ArrayObj.mqh>
class Test : public CObject
{
public:
   int               a;
   double            b;
   datetime          c;
   Test(){};
   Test(int ai){this.a = ai;}
};
int COUNT = 1000000;

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279
 
void OnStart()
{
   Print(MQLInfoInteger(MQL_MEMORY_USED));
   _BV(FooV1(), 1);
   Print(MQLInfoInteger(MQL_MEMORY_USED));
   _BV(FooV3(), 1);
   Print(MQLInfoInteger(MQL_MEMORY_USED));
}

void FooV1()
{
   Test array[];
   ArrayResize(array, COUNT);
   for(int i = 0; i < COUNT; i++)
      array[i] = Test(MathRand());
}

void FooV3()
{
   Test* array[];
   ArrayResize(array, COUNT);
   for(int i = 0; i < COUNT; i++)
      array[i] = new Test(MathRand());
   for(int i = 0; i < COUNT; i++)
      delete (array[i]);
}


1
Alert: Bench_Stack = 0, 1 <= Time[Test19.mq5 532 in OnStart: FooV1()] = 108805 mcs.
1
Alert: Bench_Stack = 0, 1 <= Time[Test19.mq5 534 in OnStart: FooV3()] = 116705 mcs.
123

De onde vêm 123 megabytes depois da V3, não sei.

 

Aqui estão as funções idênticas para comparação:

void f1(){
   CX x[10];
}

void f2(){
   CX * x[10];
   for(int i=0;i<10;i++){
      x[i]=new CX();   
   }
   for(int i=0;i<10;i++){
      delete x[i]; 
   }
}