title: Efficient assignment of a STL vector to another STL vector (WSL Issue)
body: <p>I have an issue regarding the time in which the assignment of STL vector is done. </p>
  
  <p><strong>The context is:</strong> I'm reading a binary file into a <code>std::vector</code> like this: </p>
  
  <pre><code>std::vector&lt;float&gt; read_file(const std::string &amp;file_path) {
  
      std::ifstream stream(file_path);
  
      if (!stream.good()) {
          std::cout &lt;&lt; "Cannot open file located at: " &lt;&lt; file_path &lt;&lt; std::endl;
          return std::vector&lt;float&gt;();
      }
  
      stream.seekg(0, std::ios_base::end);    
      auto size = stream.tellg();
      stream.seekg(0, std::ios_base::beg);
  
      std::vector&lt;float&gt; values(size / sizeof(float));
      stream.read((char*) &amp;values[0], size);
  
      stream.close();
  
      return values;
  }
  </code></pre>
  
  <p>I have <strong>128 binary files</strong> and each one contains <strong>~2.500.000 float</strong> values. </p>
  
  <p>Eventually I will have <strong>128</strong> x <code>std::vector&lt;float&gt;</code> vectors. However I want them stored in a list/vector (matrix should say) which turns into this data structure: <code>std::vector&lt;std::vector&lt;float&gt;&gt;</code>.</p>
  
  <p><strong>The problem is:</strong></p>
  
  <p><strong>Example 1:</strong> The execution time of this code snippet will take <strong>~700ms</strong>:</p>
  
  <pre><code>std::vector&lt;float&gt; data;
  for (int i = 1; i &lt;= 128; ++i) {
      data = read_file(getFile(i));
  }
  </code></pre>
  
  <p><strong>Example 2:</strong> But, the execution time of this code snippet will take <strong>~2000ms</strong>:</p>
  
  <pre><code>std::vector&lt;std::vector&lt;float&gt;&gt; data(128);
  for (auto i = 1; i &lt;= 128; ++i) {
      data[i-1] = read_file(getFile(i));
  }
  </code></pre>
  
  <p>From my understanding, the assignment will perform a moving operation if the right side is a <code>vector&amp;&amp;</code> and a copying operation if the right side is <code>const vector&amp;</code>. Taking into account the RVO it's worthless to add a <code>std::move</code> to the return type, hence the value returned will not be copied but moved. However the assignment in both examples should do the same thing: assign the address of the returned vector (the right side) to the vector on the left side.</p>
  
  <p><strong>Question</strong>: Based on my understanding (which may be wrong) and taking into account the both examples, why there is such a big difference in execution time between <em>Example1</em> and <em>Example2</em> if both perform the same operation (<strong>the optimizations were activated</strong>). Is there any improvement I can make to reduce the time of the second example? (I want to make the second example as efficient as possible)</p>
  
  <p>Thanks.</p>