Advertisement
Guest User

Untitled

a guest
Jan 31st, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. //Using method of clearing with WriteAllText and writing with Stream.Write
  2. // 7262 ms
  3. // 5410 ms
  4. // 7775 ms
  5. // 7151 ms
  6. // 6854 ms
  7. public static void Main(string[] args)
  8. {
  9.     using (FileStream fs = new FileStream(path + "\\Source.txt", FileMode.Open, FileAccess.Read))
  10.     {
  11.         fileToRead = new byte[fs.Length];
  12.         fs.Read(fileToRead, 0, fileToRead.Length);
  13.     }
  14.  
  15.     System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
  16.     watch.Start();
  17.  
  18.     while (iteration < 10)
  19.     {
  20.         File.WriteAllText(path + "\\Dest" + iteration.ToString() + ".txt", string.Empty);
  21.         using (Stream file = File.OpenWrite(path + "\\Dest" + iteration.ToString() + ".txt"))
  22.         {
  23.                 file.Write(fileToRead, 0, fileToRead.Length);
  24.         }
  25.         iteration++;
  26.     }
  27.  
  28.     watch.Stop();
  29.     Console.WriteLine("Watch1::Elapsed:" + watch.ElapsedMilliseconds);
  30.  
  31.     Console.ReadLine();
  32. }
  33.  
  34. //using File.WriteAllBytes
  35. // 7563 ms
  36. // 7460 ms
  37. // 7741 ms
  38. // 7598 ms
  39. // 7502 ms
  40. public static void Main(string[] args)
  41. {
  42.     using (FileStream fs = new FileStream(path + "\\Source.txt", FileMode.Open, FileAccess.Read))
  43.     {
  44.     fileToRead = new byte[fs.Length];
  45.     fs.Read(fileToRead, 0, fileToRead.Length);
  46.     }
  47.  
  48.     System.Diagnostics.Stopwatch watch2 = new System.Diagnostics.Stopwatch();
  49.     watch2.Start();
  50.  
  51.     while (iteration < 10)
  52.     {
  53.     File.WriteAllBytes(path + "\\Dest" + iteration.ToString() + ".txt", fileToRead);
  54.     iteration++;
  55.     }
  56.  
  57.     watch2.Stop();
  58.     Console.WriteLine("Watch2::Elapsed:" + watch2.ElapsedMilliseconds);
  59.     Console.ReadLine();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement