What is faster, and how can I measure such things? : <pre><code>using System.Collections.Generic;
using System.IO
</code></pre>

<p>Which variant is faster?</p>

<p>This?</p>

<pre><code>List&lt;short&gt; a = new List&lt;short&gt;();
a.Add(0);
a.Add(1);
a.Add(2);
FileStream fs = new FileStream("file", FileMode.OpenOrCreate, FileAccess.Write){
    using ( BinaryWriter bw = new BinaryWriter(fs)){
        foreach ( short b in a ){
        bw.Write(b);
        }
    }
}
</code></pre>

<p>or this?</p>

<pre><code>string a = "";
a += "0";
a += "1";
a += "2";
File.WriteAllText("file", a);
</code></pre>

<p>or this?</p>

<pre><code>short[] a = new short[3];
a[0] = 0;
a[1] = 1;
a[2] = 2;
FileStream fs = new FileStream("file", FileMode.OpenOrCreate, FileAccess.Write){
using ( BinaryWriter bw = new BinaryWriter(fs)){
    foreach ( short b in a ){
        bw.Write(b);
    }
}
</code></pre>

<p>}</p>

<p>I would like to know how fast each of these pieces of code compiles, and and how can I measure the speed myself.</p>
