In my own project, I need to write 65536 files multiple times at the same time.
If you open all the files first, repeat the writing, and close all the files. It takes about 16 minutes to complete the first write operation, and 40 minutes to complete the second write operation. The test is not continued.
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 during the write operation, close it after writing. All write operations are completed at about 2 minutes 30 seconds.
Loop
{
For (int I = 0; I <65536; I ++)
{
Open;
Write;
Close;
}
}
Therefore, the performance of the second method is far greater than that of the first method. Opening all files at a time requires a large amount of memory. The most important thing is. when processing filestream, net may need to allocate and recycle a large amount of memory, consuming a large amount of memory and resources.
In addition, I also conduct a test. If the number of files is small, the first type of performance will be much better than the second type.