Python中文
首页
教程
问答
标签
搜索
登录
注册
为什么是python哈希库.md5比linux coreutils md5sum快
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我刚找到Python哈希库.md5可能比coreutils md5sum快。在</p> <p>python哈希库</p> <pre><code>def get_hash(fpath, algorithm='md5', block=32768): if not hasattr(hashlib, algorithm): return '' m = getattr(hashlib, algorithm)() if not os.path.isfile(fpath): return '' with open(fpath, 'r') as f: while True: data = f.read(block) if not data: break m.update(data) return m.hexdigest() </code></pre> <p>coreutils md5sum公司</p> ^{pr2}$ <p>有4列关于我的测试结果计算md5和sha1的时间。在</p> <p>第1列是coreutils md5sum或sha1sum的校准时间。在</p> <p>第2列是python hashlib md5或sha1的cal time,通过读取<strong>1048576</strong>chunk。在</p> <p>第3列是python hashlib md5或sha1的cal time,通过读取<strong>32768</strong>chunk。在</p> <p>第4列是python hashlib md5或sha1的cal time,通过读取<strong>512</strong>chunk。在</p> <pre><code>4.08805298805 3.81827783585 3.72585606575 5.72505903244 6.28456497192 3.69725108147 3.59885907173 5.69266486168 4.08003306389 3.82310700417 3.74562311172 5.74706888199 6.25473690033 3.70099711418 3.60972714424 5.70108985901 4.07995700836 3.83335709572 3.74854302406 5.74988412857 6.26068210602 3.72050404549 3.60864400864 5.69080018997 4.08979201317 3.83872914314 3.75350999832 5.79242300987 6.28977203369 3.69586396217 3.60469412804 5.68853116035 4.0824379921 3.83340883255 3.74298214912 5.73846316338 6.27566385269 3.6986720562 3.6079480648 5.68188500404 4.10092496872 3.82357311249 3.73044300079 5.7778570652 6.25675201416 3.78636980057 3.62911510468 5.71392583847 4.09579920769 3.83730792999 3.73345088959 5.73320293427 6.26580905914 3.69428491592 3.61320495605 5.69155502319 4.09030103683 3.82516098022 3.73244214058 5.72749185562 6.26151800156 3.6951239109 3.60320997238 5.70400810242 4.07977604866 3.81951498985 3.73287010193 5.73037815094 6.26691818237 3.72077894211 3.60203289986 5.71795105934 4.08536100388 3.83897590637 3.73681998253 5.73614501953 6.2943251133 3.72131896019 3.61498594284 5.69963502884 (My computer has 4-core i3-2120 CPU @ 3.30GHz, 4G memory. The file calculated by these program is about 2G in size. The odd rows are about md5 and the even rows are about sha1. The time in this table are in second.) </code></pre> <p>经过100多次测试,我发现python hashlib总是比md5sum或sha1sum快。在</p> <p>我还阅读了一些源代码中关于Python2.7/Modules/{md5.c,md5.h,md5module.c}和gnulib lib/{md5.c,md5.h}的文档。它们都是MD5(rfc1321)的实现。在</p> <p>在gnulib中,<strong>32768</strong>读取的md5块。在</p> <p>我对md5和C源代码了解不多。有人能帮我解释一下这些结果吗?在</p> <p>我想问这个问题的另一个原因是,许多人认为md5sum比python_hashlib更快,他们更喜欢在编写python代码时使用md5sum。但这似乎是错误的。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我不确定您到底是如何计时的,但是这种差异很可能是因为您每次调用<code>shell_hash</code>时花在启动子进程上的时间(同样考虑<code>shlex.split</code>的解析时间)。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
3 回答
如何在python中从数据帧列表中删除引号
3 回答
如何在python中从数据帧创建列表
4 回答
如何在Python中从数据帧创建嵌套的JSON
3 回答
如何在Python中从数据帧显示wordcloud
8 回答
如何在Python中从数据帧的时间戳中删除字符
9 回答
如何在Python中从数据帧绘制简单绘图?
8 回答
如何在python中从数据帧行提取具有特定长度的范围?
8 回答
如何在python中从数据帧设置dict中的值
4 回答
如何在Python中从数据库中获得一个结果
6 回答
如何在python中从数据框中绘制分类条形图
9 回答
如何在Python中从数据框中选择特定细节?
5 回答
如何在python中从数据集中删除unicode
10 回答
如何在python中从数据集中删除某些数值?
1 回答
如何在python中从数据集中选择行
1 回答
如何在Python中从数组中删除元素
8 回答
如何在python中从数组中删除单个倒逗号?
9 回答
如何在python中从数组中删除对象?
1 回答
如何在python中从数组中删除引号
2 回答
如何在python中从数组中删除所有最小值
2 回答