Hi,
I've got a program (see source below) that makes a file and fills it with
random binary values (from 0 to 255). The source below works, however the
program creates files at a rate of about 0.5MB per second. There is a
serious performance issue with this program.
There is a loop within the main loop that generates a buffer of 500 Bytes
that are then all written at once.
Can anybody tell me how I can improve the performance of the program? Idealy
I could with a rate of about 25Mb/s.
Thanx Josh
('reps' is the number of repetitions. e.g. Number of bytes)
FileStream fs = new FileStream(fileLocation, FileMode.CreateNew);
// Create the writer for data.
BinaryWriter w = new BinaryWriter(fs);
Random r =new Random();
for (int i = 0; i < Int32.Parse(reps.ToString()); )
{
byte[] bits = new byte[500];
for (int j = 0; j <= 499; j++)
{
bits[j] = byte.Parse(r.Next(0, 255).ToString());
i++;
if(i >= Int32.Parse(reps.ToString()))
{
break;
}
}
w.Write(bits);
}