From: Eric S. Raymond Date: Mon, 25 Aug 2003 00:01:27 +0000 (+0000) Subject: We now have a verbose option and can time things. X-Git-Tag: 1.0~154 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0be720108f7fa12dd763987aa39b9c627a718598;p=comparator.git We now have a verbose option and can time things. --- diff --git a/shredcompare.py b/shredcompare.py index a75fce0..9239201 100755 --- a/shredcompare.py +++ b/shredcompare.py @@ -39,9 +39,10 @@ # # In this implementation, lines are preprocessed to remove whitespace # differences. -import sys, os, os.path, re, md5, getopt +import sys, os, os.path, re, md5, getopt, time shredsize = 5 +verbose = False ws = re.compile(r"\s+") # These just make the code more readable. @@ -68,6 +69,8 @@ def smash_whitespace(line): def shredfile(file, tree): "Build a dictionary of shred tuples corresponding to a specified file." + if verbose: + print file shreds = {} fp = open(file) lines = map(smash_whitespace, fp.readlines()) @@ -130,14 +133,24 @@ def shredcompare(tree1, tree2): if __name__ == '__main__': try: - (optlist, args) = getopt.getopt(sys.argv[1:], 's:') + (optlist, args) = getopt.getopt(sys.argv[1:], 's:v') except getopt.GetoptError: sys.stderr.write("usage: shredcompare [-s shredsize] tree1 tree2\n") sys.exit(2) for (opt, val) in optlist: if opt == '-s': shredsize = int(val) + elif opt == '-v': + verbose = True + starttime = time.time() matches = shredcompare(args[0], args[1]) + endtime = time.time() + if verbose: + elapsed = endtime - starttime + hours = elapsed/3600; elapsed %= 3600 + minutes = elapsed/60; elapsed %= 60 + seconds = elapsed + print "Done in %dh, %dm, %ds" % (hours, minutes, seconds) for (source, target) in matches: print source, "->", target