.net - What is the fastest way to create a checksum for large files in C# -
I have to sync large files in some machines. Files can be up to 6 GB size, the sync will be done manually for every few weeks. I can not take into account the filename because they can change at any time.
My plan is to create a checksum on the destination PC and on the source PC and copy all the files with a checksum, which are not already in the destination, for the destination. My first attempt was something like this:
using System.IO; Using System.Security.Cryptography; Private Static String GetChecksum (string file) {(file stream stream = file. Opener (file)} {SHA256 managed shah = new SHA256 managed (); Byte [] checksum = sha.ComputeHash (stream); Return BitConverter.ToString (checksum). Change ("-", String.Empty); }}
The problem was runtime:
- with SHA256 with 1.6 GB file -> for 20 minutes - with MD5 with a 1,6 GB file -> 6.15 min
What better way to get the checksum (can also be a better hash function)?
The problem here is that To speed things up (2 minutes for 2 GB for 2 hours for 2 minutes) SHA256 with my machine, 1 minute for MD5) SHA256 managed
reads 4096 bytes at a time (Inherit from filestream
and override (byte [], int, int) to see how small this buffer is for the iiOi).
FileStream
in BufferedStream
Wrap and set the proper-size buffer size (I tried with 1 Mb buffer):
// is not sure that the bufferstream block is used
Comments
Post a Comment