title: push_back to vector in c++ vs add to list in c#
body: <p>I have 1 code in C++ and 1 in c#</p>
  
  <p>I should emphasize that I just measured time around one .push-back and one .add and for their 10000 occurrences I write the time spent. so rest of the code has no importance. I just wrote them for clarification.</p>
  
  <p>the c++ code</p>
  
  <pre><code>void pv(int depth, m1* prevM1)
  {
      if (depth == 0)
          return;
      vector &lt;m1&gt; *mList;
      if (prevM1-&gt;childM1 != 0)
          mList = prevMove-&gt;childM1;
      else 
      {
          mList = new vector&lt;m1&gt;;   
          f1 (mList);
      }
      for(vector&lt;m1&gt;::iterator it=mList.begin(); it !=m1.end(); ++it)
      {
           pv(depth - 1 ,it.chilM1);
      }
      prevM1-&gt;childM1 = mList;
  }
  
  
  
  void f1(vector&lt;m1&gt;* Moves)
  {
  </code></pre>
  
  <p>//I have a counter and a time around this push_back. when it reaches 10000 times I print time</p>
  
  <pre><code>    m1 obj;
      Moves-&gt;push_back(obj);
  </code></pre>
  
  <p>// and Here</p>
  
  <pre><code>    m1 obj2;
      Moves-&gt;push_back(obj2);
      m1 obj3;
      Moves-&gt;push_back(obj3);
      m1 obj4;
      Moves-&gt;push_back(obj4);
      m1 obj5;
      Moves-&gt;push_back(obj5);
      m1 obj6;
      Moves-&gt;push_back(obj6);
      m1 obj7;
      Moves-&gt;push_back(obj7);
      m1 obj8;
      Moves-&gt;push_back(obj8);
      m1 obj9;
      Moves-&gt;push_back(obj9);
      m1 obj10;
      Moves-&gt;push_back(obj10);
  }
  </code></pre>
  
  <p>--------> I execute this in main</p>
  
  <pre><code>m1 move;
  PV(10, &amp;Moves);
  </code></pre>
  
  <p>the c# code</p>
  
  <pre><code>m1 f1()
  {
      List&lt;m1&gt; Moves = new List&lt;m1&gt;();
  </code></pre>
  
  <p>//I have a counter and a time around this Add. when it reaches 10000 times I print time</p>
  
  <pre><code>    m1 obj = new m1();
      Moves.Add(obj);
  </code></pre>
  
  <p>//and here</p>
  
  <pre><code>    m1 obj2 = new m1();
      Moves.Add(obj2);        
      m1 obj3 = new m1();
      Moves.Add(obj3);        
      m1 obj4 = new m1();
      Moves.Add(obj4);        
      m1 obj5 = new m1();
      Moves.Add(obj5);        
      m1 obj6 = new m1();
      Moves.Add(obj6);        
      m1 obj7 = new m1();
      Moves.Add(obj7);        
      m1 obj8 = new m1();
      Moves.Add(obj8);        
      m1 obj9 = new m1();
      Moves.Add(obj9);        
      m1 obj10 = new m1();
      Moves.Add(obj10);
      return Moves;    
  }
  
  void PV(int depth,m1 prevM1)
  {
      List&lt;m1&gt; mList;
      if (depth == 0)
      {
          return;
      }
      if (prevMove.childM1 != null)
      {
          mList = prevMove.childM1;
      }
      else
      {
          mList = f1();
      }
      foreach(m1 move in mList)
      {
          pv(depth - 1, move);
      }
  </code></pre>
  
  <p>--------> I execute this in main</p>
  
  <pre><code>m1 move;
  PV(10, move); 
  </code></pre>
  
  <p>and m1 class is same in both c++ and c#
  in C#</p>
  
  <pre><code>class m1
  {
      public String ms;
      public List&lt;m1&gt; childM1;
      public double d;
  }
  </code></pre>
  
  <p>in c++</p>
  
  <pre><code>class m1
  {
      public:
          string ms;
          m1* childM1;
          double d;
  }
  </code></pre>
  
  <p>the code in c# executed in 12 milliseconds but code in c++ executed in 143 milliseconds. I run it lots of time to be sure of the difference. the code in c++ was at least 10 times slower than the code in c#. as vector in c++ is same as List in c# it seems I missed something so I found this difference.</p>
  
  <p>Any help would highly welcomed.</p>