]> thyrsus.com Git - comparator.git/commitdiff
We now have a verbose option and can time things.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 25 Aug 2003 00:01:27 +0000 (00:01 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 25 Aug 2003 00:01:27 +0000 (00:01 +0000)
shredcompare.py

index a75fce08dacfaa5b3b7dad632f7ff0a43437af67..9239201090afbdae2664a65ac751c7e20d9242d1 100755 (executable)
 #
 # 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