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

 
Artyom Trishkin:

The rest of us so far have only the audacity to laugh and point the finger.

Really? Here's an alternative point of view.

A man came to a thread about which he had no idea, and he was immediately asked to leave it, and he made a mess of it, dragging it to his favourite turf.

he ended up moving to a separate branch and came up with an incomprehensible problem that has nothing to do with the generics being discussed in that branch or with the practice.

He did not even respond to attempts to point out errors with nonsense.

This is not the first time he has done so.

Oh, you poor bastard.

Maybe you are also one of those who search by array sorting and do not understand what is going on?

 
Комбинатор:

seriously? here's an alternative point of view.

A man came to a thread about which he had no idea, and he was immediately asked to leave it, and he took it to his favourite hobby.

he ended up moving to a separate branch and came up with an incomprehensible problem that has nothing to do with the generics being discussed in that branch or with the practice.

He did not even respond to attempts to point out errors with nonsense.

This is not the first time he has done so.

Oh, you poor bastard.

Maybe you are also one of those who search by array sorting and do not understand what is going on?


You know, a long time ago I first learned how to program - and then I found out that there are textbooks on programming. It was the same with mastering OOP and other things.

Still, a fact is a fact. No one gave an example.

Two examples with and without using sheets (i.e. without classes).

Of course, without any use of string array (this is for the variant without the class).

 

well the question of sorting is always relevant - are there options for faster sorting than the standard function and in general what is the code? .... as far as I remember there are different ways of sorting depending on the size of the array to be sorted - and the possibility of using additional memory to speed up

 

It would be interesting to see the best performing algorithms in numbers, at least in terms of execution time.

So far, it looks like we are defending our version as the best.

However, the criteria for this self-assessment are unclear.

 
Комбинатор:

seriously? here's an alternative point of view.

A man came to a thread about which he had no idea, and he was immediately asked to leave it, and he took it over to his favourite subject.

he ended up moving to a separate branch and came up with an incomprehensible problem that has nothing to do with the generics being discussed in that branch or with the practice.

He did not actually solve the problem. What is more, he is delusional when trying to point out errors.

This isnot the first time he has done so.

Oh, you poor bastard.

Maybe you are also the kind of person who does maximum array sorting and just doesn't understand what's going on?

Yes, I agree... It was expected, but what I wanted from Peter was quite different (if you try to analyze what I offered him, my goal will be clear)

And I agree with that. But the thread was created for a different purpose - to show, to discuss.

But not to laugh. What's that got to do with being offended? It's a farce. First Peter started it at Vasily's, I asked him here for a quiet discussion, and not just Peter's. The idea was different - not to poke fun at misconceptions, but to tell, to explain... And, what is more interesting - to try to come up with interesting algorithms. Do you understand? No?

:))) Of course. I don't know about that :)))

 
Renat Akhtyamov:

It would be interesting to see the best performing algorithms in numbers, at least in terms of execution time.

So far it seems to be all about defending one's own version as the best.

However, the criteria of such self-assessment are not clear.

There - I think a lot of people would be interested in that.

Well, everyone knows that Peter, stubbornly in his ego, proves strangeness - and everyone is fed up with it.

Personally, I'd like Peter to direct his persistence in a different direction - not to start a vegetable garden, but to understand what he is being offered.

 
Artyom Trishkin:

There - I think a lot of people would be interested in that.

Well, the fact that Peter, staring at his own self, proves strangeness - everyone knows here, and everyone is sick of it.

Personally, I'd like Peter to direct his persistence in a different direction - not to start a vegetable garden, but to understand what he is offered.

Time spent on operation of any algorithm is easier to predict/calculate by knowing time of function execution, e.g. repeating it 10 000 times.

But I have not encountered the problem of not completing the code to the very end, no matter how complicated it is.

As they say - bravo MQL!
 
Artyom Trishkin:

There - I think a lot of people would be interested in that.

Well, the fact that Peter, stubborn in his own self, proves strangeness - everyone knows here, and everyone is fed up with it already.

Personally, I would like Peter to direct his persistence in a different direction - not to start a vegetable garden, but to understand what is offered to him.

No one is against helping and explaining, etc. But Peter in so many threads reduces everything to the same thing that there is no desire to explain and help.
 
Alexey Oreshkin:
No one is against helping and explaining etc. But Peter in so many threads is reducing everything to the same thing, that there is no desire to explain and help.

 
Artyom Trishkin:

So far all I see here is a mockery of the man who had the audacity to post his decision here.

Obviously, it's... to put it mildly, it's a complete waste of time. But he did. The rest have so far only the courage to laugh and point the finger.


#include <Generic\ArrayList.mqh>


//+------------------------------------------------------------------+
//|  Defines                                                                |
//+------------------------------------------------------------------+

#define  TEST_LOG true
      
#define  TEST_START(NAME) string TEST_START_STRING_INFO_##NAME = StringFormat("%s, Step:%s, Test was started....", __FUNCTION__, string(NAME));  \
                         if (TEST_LOG) Print(TEST_START_STRING_INFO_##NAME);                                                                                  \
                         ulong TEST_TIMER_##NAME = GetMicrosecondCount();                                                                 
                          
#define  TEST_END(NAME)   ulong TEST_DURATION##NAME = GetMicrosecondCount() - TEST_TIMER_##NAME;                                                                                \
                         string TEST_END_STRING_INFO_##NAME = StringFormat("%s, Step:%s, Test has been finished. Duration: %I64i.", __FUNCTION__, string(NAME), TEST_DURATION##NAME);  \
                         if (TEST_LOG) Print(TEST_END_STRING_INFO_##NAME);
                         
#define  TEST_DURATION(NAME)  TEST_DURATION##NAME


#define  TEST_ERROR_INVALID_VALUE(NAME) string TEST_ERROR_STRING_INFO_##NAME = StringFormat("%s, Step:%s, Getting value does not match the original one.", __FUNCTION__, string(NAME));    \
                                 if (TEST_LOG) Print(TEST_ERROR_STRING_INFO_##NAME);                                                                                                              \
                                 DebugBreak();                                                                                                                                      \
                                 break;                                                                                          
                                 
#define  TEST_ERROR_NULL_GENERATOR(NAME) string TEST_ERROR_STRING_INFO_##NAME = StringFormat("%s, Was not found correspond Generator class - %s. Please implement it.", __FUNCTION__, string(NAME));  \
                                 if (TEST_LOG) Print(TEST_ERROR_STRING_INFO_##NAME);




//+------------------------------------------------------------------+
//|   Generators                                                               |
//+------------------------------------------------------------------+

template<typename T>
interface IGenerator{
   T GetNext(int index);
};

class IntGenerator : public IGenerator<int>{
   int GetNext(int index){return index;}
};


// TODO bypass the problem with explicit template specialization
template<typename T>
IGenerator<T>* CreateGenerator(){
   string generatorName = typename(T);
   StringToUpper(generatorName);
   
   if (generatorName == "INT"){
      return new IntGenerator();
   }
    
   return NULL;
}

//template<>
//IGenerator<int>* CreateGenerator<int>(){
//   return NULL;
//};




//+------------------------------------------------------------------+
//|    TestCollection Interfaces                                                              |
//+------------------------------------------------------------------+

template<typename T>
interface ITestRandomAccessCollection{
   bool Add(T value);
   T GetValue(int index);
};



//+------------------------------------------------------------------+
//|    TestCollection Implementations                                                   |
//+------------------------------------------------------------------+

template<typename T>
class TestRandomAccessCollectionCArrayList : public ITestRandomAccessCollection<T>{
   CArrayList<T> collection;

public:
   TestRandomAccessCollectionCArrayList(){};
   TestRandomAccessCollectionCArrayList(int capacity):collection(capacity){};
   
   bool Add(T value){
      return collection.Add(value);
   };
   T GetValue(int index){
      int value = -1; 
      collection.TryGetValue(index,value); 
      return value;
   };
};




//+------------------------------------------------------------------+
//|    Test Functions                                                              |
//+------------------------------------------------------------------+

template<typename T>
ulong TestRandomAccessCollectionAfterAdding(ITestRandomAccessCollection<T> &testCollection, const int iterationCount = 1000, int srandValue = 0){
      //TODO add shared_ptr / move out generator (Dependency Injection)
      IGenerator<T>* generator = CreateGenerator<T>();
      if (generator == NULL){
TEST_ERROR_NULL_GENERATOR("FirstGenerator")
         return 0;
      }

      if (srandValue == 0)
         srandValue = int(TimeCurrent());
         
      T validationArray [];
      ArrayResize(validationArray,iterationCount);
      

      for(int i = 0; i < iterationCount; i++){
         T value = generator.GetNext(rand());
         testCollection.Add(value);
         validationArray[i] = value;
      }
      
TEST_START ("GetValue")
      for(int i = 0; i < iterationCount; i++){
         int index = rand() % iterationCount;
         
         T value = testCollection.GetValue(index);
         T originalValue = validationArray[index];
         if (value != originalValue){
TEST_ERROR_INVALID_VALUE("Validate")
         }
      }
TEST_END ("GetValue")
      return TEST_DURATION("GetValue");
}




int OnInit()
{
  ulong result;
  
  // TODO average result
  {
     printf ("TestRandomAccessCollectionAfterAdding: Started.", result);
     TestRandomAccessCollectionCArrayList<int> testCollection();
     result = TestRandomAccessCollectionAfterAdding(testCollection, 10000, 1);
     printf ("TestRandomAccessCollectionAfterAdding: Fineshed. Total result: %I64i\n", result);
  }
  
  
  //TestArrayListRandomAccessDuringAdding(10000);
  return INIT_FAILED;
}
Reason: