Created
February 21, 2018 05:59
-
-
Save brandonio21/30fe3c81a6e763c9aaba047e70a78ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import time | |
def files_are_equal(contents1, contents2): | |
for b1, b2 in zip(contents1, contents2): | |
if b1 != b2: | |
return False | |
return True | |
def content(filename): | |
with open(filename, 'rb') as f: | |
return f.read() | |
content1 = content('largefile') | |
content2 = content('largefile2') | |
content3 = content('largefile3') | |
start = time.time() | |
print("One and two are equal: {}".format( | |
files_are_equal(content1, content2))) | |
print("One and three are equal: {}".format( | |
files_are_equal(content1, content3))) | |
end = time.time() | |
print("Content comparison took: {}".format(end - start)) | |
start = time.time() | |
hash1 = hashlib.md5(content1).hexdigest() | |
hash2 = hashlib.md5(content2).hexdigest() | |
hash3 = hashlib.md5(content3).hexdigest() | |
print("One and two are equal: {}".format(hash1 == hash2)) | |
print("One and three are equal: {}".format(hash1 == hash3)) | |
end = time.time() | |
print("Hash comparison took: {}".format(end - start)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment