I am working on a SHA1 checksum of 15,000 images (40 KB - 1.0 MB each, just 1.8 GB). I would like to speed it up, as this will be a key operation in my program, and now it takes from 500 to 600 seconds.
I tried the following, which took 500 seconds:
public string GetChecksum(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open);
using (SHA1Managed sha1 = new SHA1Managed())
{
return BitConverter.ToString(sha1.ComputeHash(fs));
}
}
Then I thought that maybe the pieces of SHA1Managed () were too small, so I used BufferedReader and increased the size of the buffer to the size of any of the files that I read.
public string GetChecksum(string filePath)
{
using (var bs = new BufferedStream(File.OpenRead(filePath), 1200000))
{
using (SHA1Managed sha1 = new SHA1Managed())
{
return BitConverter.ToString(sha1.ComputeHash(bs));
}
}
}
It took 600 seconds.
Is there anything I can do to speed up these I / O operations, or am I stuck with what I got?
x0n . , IO, 480 .