Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using method of clearing with WriteAllText and writing with Stream.Write
- // 7262 ms
- // 5410 ms
- // 7775 ms
- // 7151 ms
- // 6854 ms
- public static void Main(string[] args)
- {
- using (FileStream fs = new FileStream(path + "\\Source.txt", FileMode.Open, FileAccess.Read))
- {
- fileToRead = new byte[fs.Length];
- fs.Read(fileToRead, 0, fileToRead.Length);
- }
- System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
- watch.Start();
- while (iteration < 10)
- {
- File.WriteAllText(path + "\\Dest" + iteration.ToString() + ".txt", string.Empty);
- using (Stream file = File.OpenWrite(path + "\\Dest" + iteration.ToString() + ".txt"))
- {
- file.Write(fileToRead, 0, fileToRead.Length);
- }
- iteration++;
- }
- watch.Stop();
- Console.WriteLine("Watch1::Elapsed:" + watch.ElapsedMilliseconds);
- Console.ReadLine();
- }
- //using File.WriteAllBytes
- // 7563 ms
- // 7460 ms
- // 7741 ms
- // 7598 ms
- // 7502 ms
- public static void Main(string[] args)
- {
- using (FileStream fs = new FileStream(path + "\\Source.txt", FileMode.Open, FileAccess.Read))
- {
- fileToRead = new byte[fs.Length];
- fs.Read(fileToRead, 0, fileToRead.Length);
- }
- System.Diagnostics.Stopwatch watch2 = new System.Diagnostics.Stopwatch();
- watch2.Start();
- while (iteration < 10)
- {
- File.WriteAllBytes(path + "\\Dest" + iteration.ToString() + ".txt", fileToRead);
- iteration++;
- }
- watch2.Stop();
- Console.WriteLine("Watch2::Elapsed:" + watch2.ElapsedMilliseconds);
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement