从目录内容中获得的计算A的时间应计算多少

  • 本文关键字:计算 时间 多少 python hash
  • 更新时间 :
  • 英文 :


我制作了一个python脚本,该脚本使用checksumdir(https://github.com/cakepietoast/checksumdir)来计算基于目录的内容的MD5哈希。计算位于机械硬盘上的350MB目录的350MB目录需要几秒钟。

计算30GB目录的哈希人需要年龄。我还没有完成,我发现12个以上的时间太长了。我不知道会导致这一点,我能想到的一件事是,350MB目录适合我的RAM内存,30GB不适合。CheckSumdir中的块大小似乎是64 * 1024(65536),从我发现Google的内容似乎是一个合理的数字。

我还发现350MBDIR包含466个文件,而30GB DIR包含22696个文件。如果我推断我仍然无法解释所需的时间。

fwiw:我想使用脚本查找具有重复内容的目录。我还没有找到任何这样做的应用程序。因此,我想计算哈希并在HTML文件中显示最终结果。

相关代码:

#!/usr/bin/env python3
import os
import re
from checksumdir import dirhash # https://pypi.python.org/pypi/checksumdir/1.0.5
import json
import datetime

now = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M")
results = {}
sorted_results = {}
single_entries = []
compare_files = False
compare_directories = True
space_to_save = 0
html_overview = []
html_overview.extend(['<!DOCTYPE html>','<html>','<head>','<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">','</head>','<body>','    <table style="width:90%" class="table table-hover table-striped">', '        <tr>','            <td colspan=4></td>','        </tr>'])
# Configuration
root = "/home/jeffrey/Documenten" # Root directory to start search
create_hash = True
calculate_file_folder_size = True
compare_file_folder_names = False
sort_by = "hash" # Options: hash, size, name
json_result_file = 'result_' + now + '.json'
html_result_file = "DuplicatesHtml-" + now + ".html"
only_show_duplicate_dirs = True
remove_containing_directories = True
verbose_execution = True
# Calculate size of directory recursively - http://stackoverflow.com/questions/1392413/calculating-a-directory-size-using-python
def get_size(start_path = '.'):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            total_size += os.path.getsize(fp) / 1048576 # size from bytes to megabytes
    return total_size

# Calculate comparison properties, sort and save based on os.walk for recursive search
for dirName, subdirList, fileList in os.walk(root):
    for dir in subdirList:       
        dir_name = dir
        dir = os.path.join(dirName, dir)
        if dir[0] != ".":
            if verbose_execution = True:
                print(dir)
            if calculate_file_folder_size == True:
                size = get_size(dir)       
                if verbose_execution = True:
                    print(size)
            if create_hash == True:
                hash = dirhash(dir, 'md5')
                if verbose_execution = True:
                    print(hash)      
            results[dir] = [dir_name, size, hash]

好的,所以我发现1个文件或多或少只是悬挂该过程。我发现,通过使用另一个Python函数来计算具有详细输出的哈希。当我删除该文件时(我不需要它,Windows中的AppData Dir中的某些内容)一切都很好。供将来参考:使用第二代i5和SATA连接,大约900GB的数据花了半天的时间进行处理。我怀疑我/o是这里的瓶颈。但这是我期望的。

最新更新