title: Serious performance regression upon porting bubble sort from C to Rust
body: <p>I'm not really a programmer and very new to Rust so I assume I'm doing something wrong here. While sorting an array of 1M bytes my Rust function takes 3.5s and the C function only takes 0.2s. This is too big difference for me to believe that Rust is just that much slower. Need sanity check of my code please, what am I missing? I tried replacing the Rust <code>swap</code> function call with directly swapping values like I have done in the C implementation but it makes run even slower.</p>
  <p>Rust implementation:</p>
  <pre><code>fn sort_bubble(sample: &amp;mut Vec&lt;u8&gt;) -&gt; &amp;mut Vec&lt;u8&gt; {
      let mut updated = true;
      let sample_len = sample.len();
      let mut i;
  
      while updated {
          i = 0;
          updated = false;
          while i &lt; sample_len - 1 {
              if sample[i + 1] &lt; sample[i] {
                  sample.swap(i, i + 1);
                  updated = true;
              }
              i += 1;
          }
      }
  
      sample
  }
  </code></pre>
  <p>C implementation:</p>
  <pre><code>u_int8_t* sort_bubble(u_int8_t* sample, int sample_len)
  {
      char updated = 1;
  
      while(updated) {
          int i = 0;
          updated = 0;
          while(i &lt; sample_len - 1) {
              if(sample[i + 1] &lt; sample[i]) {
                  u_int8_t _ = sample[i];
                  sample[i] = sample[i + 1];
                  sample[i + 1] = _;
                  updated = 1;
              }
              i++;
          }
      }
  
      return sample;
  }
  </code></pre>