A project of my own that requires multiple write operations on 65,536 files at the same time.
If you open all the files first, then write them again, and then close all the files. Then it takes about 16 minutes for the first write to complete, and 40 minutes for the second time. No further tests were made.
for (int i = 0; i < 65536; i++)
{
Filestream[i] = new FileStream (buffdir+ "\" + i.tostring () + ". Dat", Filemode.create,fileaccess.write, Fileshare.write, 14000);
}
Write
Write
Write
........
for (int i = 0; i < 65536; i++)
{
Filestream[i]. Close ();
}
If only one file is opened when the write is done, close it. Then all the write operations are done in 2 minutes and 30 seconds.
Cycle
{
for (int i=0;i<65536;i++)
{
Open
Write
Close
}
}
This shows that the second method of performance is much greater than the first. Open all the files at once, need to occupy a large amount of memory, the most important is. NET in processing FileStream, you may have to do a lot of memory allocation and recycling work, consumes a lot of memory and resources.
In addition, I also do a test, if the number of files is small, then the first performance will be much better than the second.