title: Why does i32 perform better than i64 using Rust on Win8-64?
body: <p>I've recently started looking at Rust. I'm of the view that for application programs, I would prefer to use just two number-types (i64 and f64 - in general), because I think that anything that my code may run on will be 64-bit, and I believe that every line of code is important, because brevity is important, and I don't want to constantly convert numbers from eg. i32/int to i64, etc.</p>
  
  <p>Using Rust 0.8 on Win8-64: (IE: rust 0.8 host: i686-pc-mingw32).</p>
  
  <p>I wrote a minor test-program to see what the performance difference is. Given the timings that resulted, I wanted to determine why there is the difference that exists. According to the literature that I looked at, Rust will use the integer type used by the processor for addressing memory. As far as I know, on a 64-bit processor (Intel Core-i5), that is 64 bits. It would however appear that "int" on Rust is using 32-bit, and also that 32-bit appears faster than 64-bit. While I think that the difference in performance (given the number of iterations in the test) is relatively insignificant for an application-program, it still raises questions as indicated. IE: Is 32-bit int used for 64-bit processors, and why is 32-bit faster on a 64-bit machine?</p>
  
  <p>The results of my test program are as follows. The times indicated are consistent over many repeats:</p>
  
  <pre><code>1000000000 iters (i64 iters and i64 simple addition) .....
  Total Elapsed time = 3237.86 ms
  Result from i64 addition = 2000000000
  
  1000000000 iters (int iters and int simple addition) .....
  Total Elapsed time = 2353.45 ms
  Result from int addition = 2000000000
  
  1000000000 iters (i32 iters and i32 simple addition) .....
  Total Elapsed time = 2375.52 ms
  Result from i32 addition = 2000000000
  </code></pre>
  
  <p>The code used is as follows:</p>
  
  <pre><code>fn fTesti64Add(mut iIterMax:i64) -&gt; i64 {
    println(fmt!("\n%s iters (i64 iters and i64 simple addition) .....",
                 iIterMax.to_str()));
    let uTmeStart:u64 = extra::time::precise_time_ns();
    let mut iTot:i64 = 0;
    while iIterMax&gt;0 {
       iTot += 2;
       iIterMax -=1;
    }
    fDisplayElapsed(uTmeStart, extra::time::precise_time_ns());
    return iTot;
  } 
  
  fn fTestIntAdd (mut iIterMax:int) -&gt; int {
   println(fmt!("\n%d iters (int iters and int simple addition) .....", iIterMax));
   let uTmeStart:u64 = extra::time::precise_time_ns();
    let mut iVal:int = 0;
    while iIterMax &gt; 0 {
       iVal += 2;
       iIterMax -= 1;
    }
    fDisplayElapsed(uTmeStart, extra::time::precise_time_ns());
    return iVal;
  }
  
  fn fTestI32Add (mut iIterMax:i32) -&gt; i32 {
    println(fmt!("\n%s iters (i32 iters and i32 simple addition) .....",
                 iIterMax.to_str()));
    let uTmeStart:u64 = extra::time::precise_time_ns();
    let mut iVal:i32 = 0;
    while iIterMax &gt; 0 {
       iVal += 2;
       iIterMax -= 1;
    }
    fDisplayElapsed(uTmeStart, extra::time::precise_time_ns());
    return iVal;
  }
  </code></pre>