对OOP的帮助 - 页 6

 
不要忘了去除静电
 
fxsaber #:

我看不出有什么问题。

你必须把 "unlion u_Data_t "前面的 "static "删除。

static union u_Data_t
 
PapaYozh #:

所以你必须把 "unlion u_Data_t "前面的 "static "去掉。

Release: 12487.905
Debug: 9357.236

b3062.事实上,分歧的方向是错误的。

 

数字是这样的,在之前的测试之后,代码被稍微优化了。

没有静态调试和发布,最后有静态发布

174.326
13513.946
46.408
 
fxsaber #:

b3062.事实上,这种差异的方向是错误的。

所以你有一个小的差异

 
Aliaksandr Hryshyn #:

所以你有一个小的差异

在最新构建的分支中写上完整的代码和结果。这样的结构是无法通过开发商的。

 
fxsaber #:

答案最好是马上就有。并不总是有时间进行实验。

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

简而言之:没有指针会更快。我有1.2秒没有指针(V1),1.4秒有指针(V2)。1.6 - 带指针和删除(V3)。

 
用new和方法调用创建的对象比较慢...以防你不知道)))))
 
Vasiliy Sokolov #:

简而言之:没有指针会更快。我有1.2秒没有指针(V1),1.4秒有指针(V2)。1.6 - 带指针和删除(V3)。

这种比较是不正确的,因为它没有考虑到自动删除对象的时间。

经修改。

#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

V3之后的123兆字节从何而来,我不知道。

 

以下是相同的功能,以供比较。

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