Mercurial > hg
comparison contrib/perf.py @ 9826:d768614578dd
contrib/perf: profile diff of working directory changes
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Wed, 11 Nov 2009 17:02:00 +0100 |
parents | 5614a628d173 |
children | 2fcbef9a349a |
comparison
equal
deleted
inserted
replaced
9825:0d850f8beea6 | 9826:d768614578dd |
---|---|
2 '''helper extension to measure performance''' | 2 '''helper extension to measure performance''' |
3 | 3 |
4 from mercurial import cmdutil, match, commands | 4 from mercurial import cmdutil, match, commands |
5 import time, os, sys | 5 import time, os, sys |
6 | 6 |
7 def timer(func): | 7 def timer(func, title=None): |
8 results = [] | 8 results = [] |
9 begin = time.time() | 9 begin = time.time() |
10 count = 0 | 10 count = 0 |
11 while 1: | 11 while 1: |
12 ostart = os.times() | 12 ostart = os.times() |
19 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | 19 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
20 if cstop - begin > 3 and count >= 100: | 20 if cstop - begin > 3 and count >= 100: |
21 break | 21 break |
22 if cstop - begin > 10 and count >= 3: | 22 if cstop - begin > 10 and count >= 3: |
23 break | 23 break |
24 if title: | |
25 sys.stderr.write("! %s\n" % title) | |
24 if r: | 26 if r: |
25 sys.stderr.write("! result: %s\n" % r) | 27 sys.stderr.write("! result: %s\n" % r) |
26 m = min(results) | 28 m = min(results) |
27 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" | 29 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
28 % (m[0], m[1] + m[2], m[1], m[2], count)) | 30 % (m[0], m[1] + m[2], m[1], m[2], count)) |
111 timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | 113 timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
112 template='{date|shortdate} [{rev}:{node|short}]' | 114 template='{date|shortdate} [{rev}:{node|short}]' |
113 ' {author|person}: {desc|firstline}\n')) | 115 ' {author|person}: {desc|firstline}\n')) |
114 ui.popbuffer() | 116 ui.popbuffer() |
115 | 117 |
118 def perfdiffwd(ui, repo): | |
119 """Profile diff of working directory changes""" | |
120 options = { | |
121 'w': 'ignore_all_space', | |
122 'b': 'ignore_space_change', | |
123 'B': 'ignore_blank_lines', | |
124 } | |
125 | |
126 for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
127 opts = dict((options[c], '1') for c in diffopt) | |
128 def d(): | |
129 ui.pushbuffer() | |
130 commands.diff(ui, repo, **opts) | |
131 ui.popbuffer() | |
132 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
133 timer(d, title) | |
134 | |
116 cmdtable = { | 135 cmdtable = { |
117 'perflookup': (perflookup, []), | 136 'perflookup': (perflookup, []), |
118 'perfparents': (perfparents, []), | 137 'perfparents': (perfparents, []), |
119 'perfstartup': (perfstartup, []), | 138 'perfstartup': (perfstartup, []), |
120 'perfstatus': (perfstatus, []), | 139 'perfstatus': (perfstatus, []), |
125 'perftags': (perftags, []), | 144 'perftags': (perftags, []), |
126 'perfdirstate': (perfdirstate, []), | 145 'perfdirstate': (perfdirstate, []), |
127 'perfdirstatedirs': (perfdirstate, []), | 146 'perfdirstatedirs': (perfdirstate, []), |
128 'perflog': (perflog, []), | 147 'perflog': (perflog, []), |
129 'perftemplating': (perftemplating, []), | 148 'perftemplating': (perftemplating, []), |
149 'perfdiffwd': (perfdiffwd, []), | |
130 } | 150 } |
131 | 151 |