Help with OOP - page 6

 
Don't forget to remove the static
 
fxsaber #:

I don't see the problem.

You have to remove "static" before "union u_Data_t".

static union u_Data_t
 
PapaYozh #:

So you have to remove "static" before "union u_Data_t".

Release: 12487.905
Debug: 9357.236

b3062. Indeed, the divergence is in the wrong direction.

 

Figures are like this, after previous test the code was slightly optimised:

Without static debugging and release, last with static release

174.326
13513.946
46.408
 
fxsaber #:

b3062. Indeed, the discrepancy is in the wrong direction.

So you have a small difference

 
Aliaksandr Hryshyn #:

So you have a small difference

Write in the branch of the latest build with full code and results. Such a construct will not get past the developers.

 
fxsaber #:

The answer is preferably right away. There isn't always time for experimentation.

#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);
}

Briefly: it's faster without pointers. I have 1.2 sec without pointers (V1), 1.4 with pointers (V2). 1.6 - with pointers and removal (V3).

 
Objects created with new and method calls are slower... in case you didn't know)))))
 
Vasiliy Sokolov #:

Briefly: it's quicker without pointers. I have 1.2 sec without pointers (V1), 1.4 with pointers (V2). 1.6 - with pointers and removal (V3).

The comparison is incorrect because it doesn't take into account the time it takes to automatically delete objects.

Modified.

#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

Where 123 megabytes after V3 comes from, I don't know.

 

Here are the identical functions for comparison:

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]; 
   }
}