contrib/perf: profile diff of working directory changes
authorPatrick Mezard <pmezard@gmail.com>
Wed, 11 Nov 2009 17:02:00 +0100
changeset 9826 d768614578dd
parent 9825 0d850f8beea6
child 9827 4fe9ca519637
contrib/perf: profile diff of working directory changes
contrib/perf.py
--- a/contrib/perf.py	Wed Nov 04 13:44:15 2009 -0600
+++ b/contrib/perf.py	Wed Nov 11 17:02:00 2009 +0100
@@ -4,7 +4,7 @@
 from mercurial import cmdutil, match, commands
 import time, os, sys
 
-def timer(func):
+def timer(func, title=None):
     results = []
     begin = time.time()
     count = 0
@@ -21,6 +21,8 @@
             break
         if cstop - begin > 10 and count >= 3:
             break
+    if title:
+        sys.stderr.write("! %s\n" % title)
     if r:
         sys.stderr.write("! result: %s\n" % r)
     m = min(results)
@@ -113,6 +115,23 @@
                                ' {author|person}: {desc|firstline}\n'))
     ui.popbuffer()
 
+def perfdiffwd(ui, repo):
+    """Profile diff of working directory changes"""
+    options = {
+        'w': 'ignore_all_space',
+        'b': 'ignore_space_change',
+        'B': 'ignore_blank_lines',
+        }
+
+    for diffopt in ('', 'w', 'b', 'B', 'wB'):
+        opts = dict((options[c], '1') for c in diffopt)
+        def d():
+            ui.pushbuffer()
+            commands.diff(ui, repo, **opts)
+            ui.popbuffer()
+        title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
+        timer(d, title)
+
 cmdtable = {
     'perflookup': (perflookup, []),
     'perfparents': (perfparents, []),
@@ -127,5 +146,6 @@
     'perfdirstatedirs': (perfdirstate, []),
     'perflog': (perflog, []),
     'perftemplating': (perftemplating, []),
+    'perfdiffwd': (perfdiffwd, []),
 }