So I'm trying to read data and store it in an array as fast as possible and the fastest method I found of doing so was this.
var filePath = "data.dat";
FileStream fs = new FileStream(filePath, FileMode.Open);
bool[] buffer = new bool[fs.Length];
TimeSpan[] times = new TimeSpan[500000];
Stopwatch sw = new Stopwatch();
for (int r = 0; r < 500000; r++)
{
sw.Start();
int stackable = 0;
int counter = 0;
while ((stackable = fs.ReadByte()) != -1)
{
buffer[counter] = (stackable == 1);
counter++;
}
sw.Stop();
Console.WriteLine($"Elapsed: {sw.Elapsed}ms");
times[r] = sw.Elapsed;
sw.Reset();
}
Console.WriteLine($"Longest itteration: {times.Max()}ms");
which manages to read and process about 9000 bytes in < 3ms. The idea is to check each byte to see if it's either 1 or 0 (true or false) and store that in an array.
So my question is, is there a faster way of achieving this? What are some things to keep in mind when trying to process data fast, is it to make sure you're working with smaller data types so you don't allocate unecessary memory?
What the data looks like.