Skip to content

Instantly share code, notes, and snippets.

@brandonio21
Created February 21, 2018 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonio21/30fe3c81a6e763c9aaba047e70a78ebf to your computer and use it in GitHub Desktop.
Save brandonio21/30fe3c81a6e763c9aaba047e70a78ebf to your computer and use it in GitHub Desktop.
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