Skip to content

Instantly share code, notes, and snippets.

@rohanpm
Last active June 24, 2020 22:11
Show Gist options
  • Select an option

  • Save rohanpm/2c1662e39fb138869cd4901cc9b2f9d4 to your computer and use it in GitHub Desktop.

Select an option

Save rohanpm/2c1662e39fb138869cd4901cc9b2f9d4 to your computer and use it in GitHub Desktop.
# Tested over /mnt/redhat/rel-eng/OpenShiftEnterprise/4.4/images/cdn
# with realistic environment
result-both-sums.txt:real 0m13.294s
result-both-sums.txt:real 0m15.049s
result-both-sums.txt:real 0m14.133s
result-both-sums.txt:real 0m13.102s
result-both-sums.txt:real 0m14.525s
result-both-sums.txt:real 0m13.979s
result-both-sums.txt:real 0m15.156s
result-both-sums.txt:real 0m15.098s
result-both-sums.txt:real 0m13.009s
result-md5-only.txt:real 0m5.803s
result-md5-only.txt:real 0m5.308s
result-md5-only.txt:real 0m4.320s
result-md5-only.txt:real 0m6.257s
result-md5-only.txt:real 0m4.167s
result-md5-only.txt:real 0m4.937s
result-md5-only.txt:real 0m4.974s
result-md5-only.txt:real 0m4.269s
result-md5-only.txt:real 0m4.876s
result-no-sums.txt:real 0m0.789s
result-no-sums.txt:real 0m0.787s
result-no-sums.txt:real 0m0.808s
result-no-sums.txt:real 0m0.831s
result-no-sums.txt:real 0m0.803s
result-no-sums.txt:real 0m0.781s
result-no-sums.txt:real 0m0.741s
result-no-sums.txt:real 0m0.736s
result-no-sums.txt:real 0m1.206s
result-sha256-only.txt:real 0m9.606s
result-sha256-only.txt:real 0m10.604s
result-sha256-only.txt:real 0m10.876s
result-sha256-only.txt:real 0m10.786s
result-sha256-only.txt:real 0m11.937s
result-sha256-only.txt:real 0m10.118s
result-sha256-only.txt:real 0m10.904s
result-sha256-only.txt:real 0m10.816s
result-sha256-only.txt:real 0m10.892s
#!/usr/bin/env python
# Testing performance of checksum calculation.
# Usage:
#
# ./sumperf [<sumtype1> <sumtype2> ...] [<filename1> <filename2> ...]
#
# - Omit any sumtypes to test read without checksum.
# - Make sure to run it several times and/or be aware of cache
import logging
import hashlib
import sys
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
CHUNKSIZE = 1024*1024*16
LOG = logging.getLogger()
sumtypes = []
filenames = []
for arg in sys.argv[1:]:
try:
# test if it's a checksum type
hashlib.new(arg)
# OK, it is
sumtypes.append(arg)
except ValueError:
# it's not, then it ought to be a filename
filenames.append(arg)
for filename in filenames:
count = 0
hashers = [(sumtype, hashlib.new(sumtype)) for sumtype in sumtypes]
LOG.info("Begin read %s", filename)
with open(filename, 'rb') as f:
while True:
chunk = f.read(CHUNKSIZE)
if not chunk:
break
count += len(chunk)
for h in hashers:
h[1].update(chunk)
LOG.info("End read %s, bytes: %s", filename, count)
for h in hashers:
LOG.info(" %s: %s", h[0], h[1].hexdigest())
LOG.info(" ============================ \n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment