Algorithms, solution methods, comparison of their performance - page 20

 
Реter Konow:

I don't know why you would add entities to an ideal solution. I don't see the point.

You don't wear two hats at the same time. And why is that?

First, explain this. ))


"You're torturing people and making them suffer, lowering them morally and psychologically...."

Cursed World (Collected)Authors: Dmitri Ganin

 
Sergey Dzyublik:

"You do torture people and make them suffer, you lower them morally and psychologically...."

The Cursed World (collection)Authors: Dmitry Ganin

I sincerely apologize to everyone who I inadvertently made suffer morally and psychologically.

No purpose other than to find the perfect solution to a particular problem, I have not pursued.

On the contrary, I myself suffered incomprehensible attacks and unmotivated aggression.

Apparently, this is the price paid by anyone who does not want to "keep up" with society.

Well, I have made my choice and I am not blaming anyone...

 
Реter Konow:

I don't know why you would add entities to an ideal solution.


Maybe it's too early to talk about your code as an ideal solution.

And here is the actual collection of hats

 
Alexandr Andreev:

Maybe it's too early to talk about your code as a perfect solution

I was talking in general terms, so to speak...

"Why, to an ideal solution (any solution), add entities."

I must say that many people gave me very valuable ideas and pointed out the right mistakes:

1. a character count error.

2. error caused by collisions of substrings inside a common string.

3. Overflow of memory allocated for each particular string. 4.

4. False belief that changing an array size leads to data erasure.


Thank you all so much for pointing out these errors!

 
Реter Konow:
...

Thank you all so much for pointing out those mistakes!

To be objective, the last one, the ideal solution, belongs to everyone, as, I came to it thanks to pointing out mistakes, communicating and interacting with people.

 
Реter Konow:

To be objective, the last one, the ideal solution, belongs to everyone, because, I came to it through pointing out mistakes, communicating and interacting with people.


Once again, the last option is just an option, what came before was not an option at all! And the fact that it is perfect is a moot point

 
Alexandr Andreev:

Once again, the last option is just an option, what came before was not an option at all! And the fact that it's perfect is a moot point.

Okay, fine. Let it be perfect for me only. Everyone can judge it on their own scale.
 

I suggest we move on to DEBAG prints and comets - who has any thoughts?

 

tested the running time if the function is:

1. wrapped in a class

2. wrapped in a class, an instance of the class is created using the new operator

3. just call the function without using a wrapper

//+------------------------------------------------------------------+

#define    SpeedTest(count_x10,msg,EX)        {uint mss=GetTickCount(); ulong count=(ulong)pow(10,count_x10);for(ulong i=0;i<count&&!_StopFlag;i++){EX;} \
                                              printf("%s: loops=%i ms=%u",msg,count,GetTickCount()-mss);}
//+------------------------------------------------------------------+
class COpen
{
private:
   string            m_symbol;
public:
                     COpen(const string symbol): m_symbol(symbol) {}
   double            getOpen(const int bar) const                 { return(iOpen(m_symbol, 0, bar)); }

};
//+------------------------------------------------------------------+
void OnStart()
{  #define  loop_x10 9
//1.
   COpen sym1(_Symbol);
   srand(GetTickCount());
   SpeedTest(loop_x10, "1. COpen", sym1.getOpen(rand()));
//2.
   srand(GetTickCount());
   SpeedTest(loop_x10, "2. new COpen",
             COpen *sym2 = new COpen(_Symbol);
             sym2.getOpen(rand());
             delete sym2;
            );
//3.            
   srand(GetTickCount());
   SpeedTest(loop_x10, "3. iOpen",iOpen(NULL,0,rand()););            
}
//_______________________________________________________________________

2019.10.12:39:29.802 SpeedTst_class (EURUSD,M1) 1. COpen: loops=1000000000 ms=41016

2019.10.12:41:05.352 SpeedTst_class (EURUSD,M1) 2. new COpen: loops=1000000000 ms=95562

2019.10.12:41:45.939 SpeedTst_class (EURUSD,M1) 3. iOpen: loops=1000000000 ms=40578


Tests 1 and 3 are side by side in terms of performance, i.e. function call wrapping into class is not critical, test 2 has added time because of constructor and destructor calls

 

SymbolInfoDouble() execution speed test

#property version   "1.00"
// количество итераций теста
#define  LOOPx10 8

#define    SpeedTest(count_x10,msg,EX)        {uint mss=GetTickCount(); ulong count=(ulong)pow(10,count_x10);for(ulong i=0;i<count&&!_StopFlag;i++){EX;} \
                                              printf("%s: loops=%i ms=%u",msg,count,GetTickCount()-mss);}
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   double lot;

   srand(GetTickCount());
   SpeedTest(LOOPx10, "calcNormVol_my()", lot = rand() / 1000.0; calcNormVol_my(lot))

   srand(GetTickCount());
   SpeedTest(LOOPx10, "calcNormVol_alexeyvik()", lot = rand() / 1000.0; calcNormVol_alexeyvik(lot))
   
   srand(GetTickCount());
   SpeedTest(LOOPx10, "calcNormVol_fxsaber()", lot = rand() / 1000.0; calcNormVol_fxsaber(lot))
   
   srand(GetTickCount());
   SpeedTest(LOOPx10, "calcNormVol_my_2()", lot = rand() / 1000.0; calcNormVol_my_2(lot))

}
//+------------------------------------------------------------------+
double calcNormVol_my(const double value)
{
   const static string sym = _Symbol;
   return(NormalizeDouble(fmax(fmin(SymbolInfoDouble(sym, SYMBOL_VOLUME_STEP) * round(value / SymbolInfoDouble(sym, SYMBOL_VOLUME_STEP)), SymbolInfoDouble(sym, SYMBOL_VOLUME_MAX)),
                               SymbolInfoDouble(sym, SYMBOL_VOLUME_MIN)),  2));
}
//+------------------------------------------------------------------+
double calcNormVol_alexeyvik(const double value)
{
//   const string sym = _Symbol;
   return(
            NormalizeDouble(fmax(fmin(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP) * round(value / SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP)),
                                      SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX)),  SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN)), 2)
         );
}
//+------------------------------------------------------------------+
const double VolumeStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
const double VolumeMax = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
const double VolumeMin = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
const int O_DigitsInVolumeStep = 2;
double calcNormVol_fxsaber( const double value )
{
   return((value > VolumeMax) ? VolumeMax
          : ((value < VolumeMin) ? VolumeMin
             : NormalizeDouble(VolumeStep * (int)(value / VolumeStep + 0.5), O_DigitsInVolumeStep)));
}
//+------------------------------------------------------------------+
double calcNormVol_my_2( const double value )
{
   const static double volumeStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   const static double volumeMax = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
   const static double volumeMin = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   const static int o_digitsInVolumeStep = 2;
   return((value > volumeMax) ? volumeMax
          : ((value < volumeMin) ? volumeMin
             : NormalizeDouble(volumeStep * (int)(value / volumeStep + 0.5), o_digitsInVolumeStep)));
}
//+------------------------------------------------------------------+

2019.12.11 21:13:08.896 tst_volum (EURUSD,W1) calcNormVol_my(): loops=100000000 ms=173406

2019.12.11 21:15:45.425 tst_volum (EURUSD,W1) calcNormVol_alexeyvik(): loops=100000000 ms=156531

2019.12.11 21:15:45.533 tst_volum (EURUSD,W1) calcNormVol_fxsaber(): loops=100000000 ms=110

2019.12.11 21:15:45.916 tst_volum (EURUSD,W1) calcNormVol_my_2(): loops=100000000 ms=390