using System.Collections.Generic;
using System.IO
Which variant is faster?
This?
List<short> a = new List<short>();
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);
}
}
}
or this?
string a = "";
a += "0";
a += "1";
a += "2";
File.WriteAllText("file", a);
or this?
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);
}
}
}
I would like to know how fast each of these pieces of code compiles, and and how can I measure the speed myself.