当前位置:网站首页>Net question and answer: is there the most efficient way to check large files in C?
Net question and answer: is there the most efficient way to check large files in C?
2022-07-21 00:43:00 【biyusr】
Consultation area
Dario:
I need to synchronize large files between multiple machines , But the file is as high as 6G, I usually synchronize manually every few weeks , Considering that the file name of the file often changes , To check consistency , I'm thinking about using checksum
Mechanism .
My plan is to Source machine
and Target machine
Do on The checksum
, Then in the machine room copy Bring a checksum when you file , So as to judge the integrity of the document , I try to do this with the following code .
static string GetChecksum(string file)
{
using (FileStream stream = File.OpenRead(file))
{
SHA256Managed sha = new SHA256Managed();
byte[] checksum = sha.ComputeHash(stream);
return BitConverter.ToString(checksum).Replace("-", String.Empty);
}
}
Now the problem is :
SHA256 In mode ,1.6G Documents need to be consumed 20 Minutes is the checksum .
MD5 In mode ,1.6G Documentation needs 6.15 Minutes is the checksum .
Is there a more efficient way to calculate The checksum Well ?
Answer area
Anton Gogolev:
The problem is SHA256Managed
Only... Can be read at a time 4096 byte, This is for disk IO Throughput is too small .
To speed up , It can be used BufferedStream To the parcel FileStream, So as to improve FileStream default 4096 Size , However, this value can set a reasonable range according to your own scenario , Here I set it to 1M
.
// Not sure if BufferedStream should be wrapped in using block
using(var stream = new BufferedStream(File.OpenRead(filePath), 1024 * 1024))
{
// The rest remains the same
}
It's on my machine .
SHA256 In mode ,2G Documentation needs 2 minute Calculate the check sum .
MD5 In mode ,2G Documentation needs 1 minute Calculate the check sum .
Fabske:
You can get to know XxHash.Net
, github Address :https://github.com/wilhelmliao/xxHash.NET
and xxHash
The algorithm seems to be the fastest , Here is xxHash Of benchmark chart .
Specific reference github:https://github.com/Cyan4973/xxHash
Comment area
Speaking of checksum
, It reminds me of Principles of computer network
, Feeling is the most important word in this class ,TCP,UDP Bao wubu checksum, Its function is mostly afraid of losing some bytes due to interference in network transmission , such checksum Can accurately find , But I remember redis Of xxx.rdb There are also checksum
Of , This thing is really too important .
边栏推荐
- Deeply participated in opengauss Developer Day 2022, cloud and enmo showed their style in a number of activities
- The applet "getlocation:fail fail: require permission desc" failed to get the requested address
- 企业应积极探索,把握元宇宙新业态与新趋势
- Three principles CIOs should follow in order to successfully carry out digital transformation
- 央视新闻《济南开住宿手撕定额发票》新闻频道_人民网
- 浅析云边端协同架构在安防视频领域的应用意义及场景
- 解锁高评分 | eBay 深耕用户体验,优化大屏幕设备应用
- How to export tables using MySQL statements
- Persuasion failed, and the police wrote code to expose the fraud on the spot, which made me have a brain hole
- 智能问答(Question Answering)的主要研究方向
猜你喜欢
How to export tables using MySQL statements
Chapter 8: arithmetic prime sequence in interval [%d,%d], improved arithmetic prime sequence
[romance understood by technical talents] tidb community has prepared a "Tanabata Festival" gift for your partner, and everyone has a share!
EasyCVR平台针对360浏览器自动填充密码问题的解决办法
[swpu2019] web1-1 | SQL injection
如何查看Win11可以升级22h2?Win11升级22h2的方法
Protocol buffer learning
SweetAlert笔记-在弹窗中添加输入框图片等
Common interview questions for app UI automated testing may be useful~
Sweetalert notes - add input box pictures, etc. in the pop-up window
随机推荐
"Collection of Architects"
Cpolar application example helps shipping customers Telecommuting
央视新闻《苏州开餐饮手撕定额发票》新闻频道_人民网
开发者必读:2022年移动应用运营增长洞察白皮书
央视新闻《宁波开住宿手撕定额发票》新闻频道_人民网
CCTV news news news channel "Hangzhou opens catering quota invoice by hand"_ People's network
怎么使用mysql的导出语句
Internet of things communication protocols: mqtt, COAP, nb-iot, RFID, Bluetooth, NFC
gcc: error trying to exec ‘cc1‘: execvp: No such file or directory
苦劝无果,民警现场写代码揭诈骗,这事让我有一个脑洞
CCTV news "Wuhan opens catering quota invoice by hand" news channel_ People's network
CCTV news news news channel of Guangzhou catering manual tearing quota invoice_ People's network
Overwintering samples of game companies: has going to sea and boutique become a new growth point?
央视新闻《武汉开住宿手撕定额发票》新闻频道_人民网
央视新闻《郑州开住宿手撕定额发票》新闻频道_人民网
央视新闻《天津开住宿手撕定额发票》新闻频道_人民网
Web performance test needs analysis, what should we do?
Cve-2014-6271 "broken shell" vulnerability
Codeworks 5 questions per day (average 1500) - day 20
通过Shell实现MeterSphere Signature签名