Skip to content

Instantly share code, notes, and snippets.

@Jaxmetalmax
Created June 21, 2014 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaxmetalmax/7daf6a9931b4a2e685e1 to your computer and use it in GitHub Desktop.
Save Jaxmetalmax/7daf6a9931b4a2e685e1 to your computer and use it in GitHub Desktop.
// FROM http://www.codeproject.com/Tips/777322/A-Faster-File-Copy
/// <summary> Time the Move
/// </summary>
/// <param name="source">Source file path</param>
/// <param name="destination">Destination file path</param>
public static void MoveTime (string source, string destination)
{
DateTime start_time = DateTime.Now;
FMove (source, destination);
long size = new FileInfo (destination).Length;
int milliseconds = 1 + (int) ((DateTime.Now - start_time).TotalMilliseconds);
// size time in milliseconds per hour
long tsize = size * 3600000 / milliseconds;
tsize = tsize / (int) Math.Pow (2, 30);
Console.WriteLine (tsize + "GB/hour");
}
/// <summary> Fast file move with big buffers
/// </summary>
/// <param name="source">Source file path</param>
/// <param name="destination">Destination file path</param>
static void FMove (string source, string destination)
{
int array_length = (int) Math.Pow (2, 19);
byte[] dataArray = new byte[array_length];
using (FileStream fsread = new FileStream
(source, FileMode.Open, FileAccess.Read, FileShare.None, array_length))
{
using (BinaryReader bwread = new BinaryReader (fsread))
{
using (FileStream fswrite = new FileStream
(destination, FileMode.Create, FileAccess.Write, FileShare.None, array_length))
{
using (BinaryWriter bwwrite = new BinaryWriter (fswrite))
{
for (; ; )
{
int read = bwread.Read (dataArray, 0, array_length);
if (0 == read)
break;
bwwrite.Write (dataArray, 0, read);
}
}
}
}
}
File.Delete (source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment