Reputation: 564
I need to make modifications to a textfile and keep the original intact. Right now I am using a reader/writer and reading the file and then writing it back sans the modifications.
Unfortunately the text files are huge, ~2gb and are taking about an hour to complete (as the text files are on a network drive).
Would using the file.Move be faster than reading/writing? For example, move the textfiles to local machine, do the modifications, then move it back?
Or, make a copy of the original and go through and modify it that way, instead of having to read/write?
My current code :
try
{
using (StreamReader reader = new StreamReader(filePath))
{
using (StreamWriter writer = new StreamWriter(output))
{
//go through the whole txt file
while (!reader.EndOfStream)
{
//gets the line
line = reader.ReadLine();
if (!modification case goes here))
{
writer.Write(line);
}
}
}
}
}
}
Any help would be appreciated!
Upvotes: 3
Views: 313
Reputation: 1990
With attached network drives it's always faster to copy file locally, do whatever and copy it back. This way you use caching and fetch ahead (pre-caching) which is implemented at hardware level of the disk drive. Network throughput is always limited to average formula of Network_T_Rate / 10 expressed in Megabytes-per-second. So, for example, if you have 100T, as most of corporation networks, you'll get ~10Mb/s no matter read or write, as the disk on the other end is faster than network. In other words, your bottleneck is network.
Upvotes: 3