title: How to improve Vec initialization time?
body: <p>Initializing a <code>Vec</code> in Rust is incredibly slow if compared with other languages. For example, the following code</p>
  
  <pre><code>let xs: Vec&lt;u32&gt; = vec![0u32, 1000000];
  </code></pre>
  
  <p>will translate to</p>
  
  <pre><code>let xs: Vec&lt;u32&gt; = Vec::new();
  xs.push(0);
  xs.push(0);
  xs.push(0);
  // ...
  </code></pre>
  
  <p>one million times. If you compare this to the following code in C:</p>
  
  <pre><code>uint32_t* xs = calloc(1000000, sizeof(uint32_t));
  </code></pre>
  
  <p>the difference is striking.</p>
  
  <p>I had a little bit more luck with</p>
  
  <pre><code>let xs: Vec&lt;u32&gt; = Vec::with_capacity(1000000);
  xs.resize(1000000, 0);
  </code></pre>
  
  <p>bit it's still very slow.</p>
  
  <p>Is there any way to initialize a <code>Vec</code> faster?</p>