PLO - page 3

 

Without the second parameter, it is the same.

Files:
test-2.mq5  2 kb
 

There were some minor errors in your code - I corrected it and added a check output.

My result on x64:

2010.07.16 20:10:57	Test (GBPUSD,M15)	Класс:   828 результат: 0.9999999999999994
2010.07.16 20:10:56	Test (GBPUSD,M15)	Функция: 735 результат: 0.9999999999999994

Analysis of the generated code showed that function and class method calls were completely inline and actually equal to each other.

There were no function calls in the loop, and the slightly lower speed of the class is due to indirect addressing from this.


Here is the code:

class CLASS
  {
protected:
   double            prev;

public:
          CLASS() { prev=0.0; }
   double ma(double v)
     {
      prev=0.1*v+0.9*prev;
      return(prev);
     }
  };

double FUNC(double v,double prev)
  {
   prev=0.1*v+0.9*prev;
   return(prev);
  }
void OnStart()
  {
   double x;
   int    start;
   CLASS  CL;
//---
   start=GetTickCount();
   x=0;
   for(int i=0;i<100000000;i++)
     {
      x=FUNC(1,x);
     }
   Print("Функция: "+IntegerToString(GetTickCount()-start)," результат: ",x);
//---
   start=GetTickCount();
   x=0;
   for(int i=0;i<100000000;i++)
     {
      x=CL.ma(1);
     }
   Print("Класс: "+IntegerToString(GetTickCount()-start)," результат: ",x);
  }
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
  • www.mql5.com
Основы языка / Типы данных / Структуры и классы - Документация по MQL5
 

The difference between function calls and class methods can only be picked up by specially written tests like these.

In reality, using classes gives a speedup by saving on passing frequently used parameters.

Документация по MQL5: Основы языка / Типы данных / Структуры и классы
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
  • www.mql5.com
Основы языка / Типы данных / Структуры и классы - Документация по MQL5
 
Renat:

The difference between function calls and class methods can only be picked up by specially written tests like this.

In reality the use of classes gives acceleration at the expense of economy on transfer of frequently used parameters.


I agree, OOP will hardly become faster than procedural programming, unless hardware support appears :)

Well, don't mention it, I'm going to dive into OOP in mql 5, I haven't got round to it yet))

 
mrProF:

I agree, OOP will hardly become faster than procedural programming, unless there is hardware support :)

Well, don't mention it, I will dive into OOP in mql 5, I've never got around to it))

nobody needs all this OOP, except programmers who want to write an artificial brain))))

I mean, I've read the article on the first page... I don't get it... Clancy... why?

Just explain why... 30 indicators may be attached to Expert much faster... or what for)))) I do not really understand, do not be angry.

maybe it is for:




 
maryan.dirtyn:

no one needs all this OOP, except programmers who want to write an artificial brain)))

I've read the article on the first page... I don't understand it... Clasie... why?

Just explain why... 30 indicators may be attached to Expert much faster... or what for)))) I do not really understand, do not be angry.

For programmers who want to write an artificial "brain" for themselves and make traders brainless...
 

If you don't like OOP, don't use it

All basic functionality of MT5 is implemented classically as functions

And buying candy by weight or in a bag is a matter of taste

I like candies in the fridge in the shelves and wrapped in multi-coloured packaging

 
maryan.dirtyn:

no one needs all this OOP, except programmers who want to write an artificial brain)))

I've read the article on the first page... I don't get it... Clasie... why?

Just explain why... 30 indicators may be attached to Expert much faster... or what for)))) I do not really understand, do not be angry.

maybe it is for:




OOP is a good thing for large programs.
If there is less than 50 lines of code, you don't need OOP.
But when the code becomes too much, it becomes almost impossible to understand what belongs to what - only comments.
The probability of an error increases when variables are not shared as intended; it's a mess.
In OOP, variables can be stored inside a container (class) along with methods (functions).

There is no task that can be written in OOP and cannot be written without OOP.
It is a matter of convenience))

OOP is not a method of solving problems, but a way to structure code.

 

mrProF:

There is no task that cannot be written in OOP and cannot be written without OOP.

It is a matter of convenience))

OOP is not a method of solving tasks but a way of code structuring.

And that's right... :)
 

I was wrong - "There is no task which can be written in OOP and which cannot be written without OOP".

That's how I meant it))