##// END OF EJS Templates
perf: fix perfcca to work with new casecollisionauditor interface...
Joshua Redstone -
r17216:01c1ee4b default
parent child Browse files
Show More
@@ -1,252 +1,252 b''
1 1 # perf.py - performance test routines
2 2 '''helper extension to measure performance'''
3 3
4 4 from mercurial import cmdutil, scmutil, util, match, commands
5 5 import time, os, sys
6 6
7 7 def timer(func, title=None):
8 8 results = []
9 9 begin = time.time()
10 10 count = 0
11 11 while True:
12 12 ostart = os.times()
13 13 cstart = time.time()
14 14 r = func()
15 15 cstop = time.time()
16 16 ostop = os.times()
17 17 count += 1
18 18 a, b = ostart, ostop
19 19 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
20 20 if cstop - begin > 3 and count >= 100:
21 21 break
22 22 if cstop - begin > 10 and count >= 3:
23 23 break
24 24 if title:
25 25 sys.stderr.write("! %s\n" % title)
26 26 if r:
27 27 sys.stderr.write("! result: %s\n" % r)
28 28 m = min(results)
29 29 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n"
30 30 % (m[0], m[1] + m[2], m[1], m[2], count))
31 31
32 32 def perfwalk(ui, repo, *pats):
33 33 try:
34 34 m = scmutil.match(repo[None], pats, {})
35 35 timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
36 36 except Exception:
37 37 try:
38 38 m = scmutil.match(repo[None], pats, {})
39 39 timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
40 40 except Exception:
41 41 timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
42 42
43 43 def perfstatus(ui, repo, *pats):
44 44 #m = match.always(repo.root, repo.getcwd())
45 45 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
46 46 # False))))
47 47 timer(lambda: sum(map(len, repo.status())))
48 48
49 49 def clearcaches(cl):
50 50 # behave somewhat consistently across internal API changes
51 51 if util.safehasattr(cl, 'clearcaches'):
52 52 cl.clearcaches()
53 53 elif util.safehasattr(cl, '_nodecache'):
54 54 from mercurial.node import nullid, nullrev
55 55 cl._nodecache = {nullid: nullrev}
56 56 cl._nodepos = None
57 57
58 58 def perfheads(ui, repo):
59 59 cl = repo.changelog
60 60 def d():
61 61 len(cl.headrevs())
62 62 clearcaches(cl)
63 63 timer(d)
64 64
65 65 def perftags(ui, repo):
66 66 import mercurial.changelog, mercurial.manifest
67 67 def t():
68 68 repo.changelog = mercurial.changelog.changelog(repo.sopener)
69 69 repo.manifest = mercurial.manifest.manifest(repo.sopener)
70 70 repo._tags = None
71 71 return len(repo.tags())
72 72 timer(t)
73 73
74 74 def perfancestors(ui, repo):
75 75 heads = repo.changelog.headrevs()
76 76 def d():
77 77 for a in repo.changelog.ancestors(heads):
78 78 pass
79 79 timer(d)
80 80
81 81 def perfdirstate(ui, repo):
82 82 "a" in repo.dirstate
83 83 def d():
84 84 repo.dirstate.invalidate()
85 85 "a" in repo.dirstate
86 86 timer(d)
87 87
88 88 def perfdirstatedirs(ui, repo):
89 89 "a" in repo.dirstate
90 90 def d():
91 91 "a" in repo.dirstate._dirs
92 92 del repo.dirstate._dirs
93 93 timer(d)
94 94
95 95 def perfdirstatewrite(ui, repo):
96 96 ds = repo.dirstate
97 97 "a" in ds
98 98 def d():
99 99 ds._dirty = True
100 100 ds.write()
101 101 timer(d)
102 102
103 103 def perfmanifest(ui, repo):
104 104 def d():
105 105 t = repo.manifest.tip()
106 106 m = repo.manifest.read(t)
107 107 repo.manifest.mapcache = None
108 108 repo.manifest._cache = None
109 109 timer(d)
110 110
111 111 def perfchangeset(ui, repo, rev):
112 112 n = repo[rev].node()
113 113 def d():
114 114 c = repo.changelog.read(n)
115 115 #repo.changelog._cache = None
116 116 timer(d)
117 117
118 118 def perfindex(ui, repo):
119 119 import mercurial.revlog
120 120 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
121 121 n = repo["tip"].node()
122 122 def d():
123 123 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
124 124 cl.rev(n)
125 125 timer(d)
126 126
127 127 def perfstartup(ui, repo):
128 128 cmd = sys.argv[0]
129 129 def d():
130 130 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
131 131 timer(d)
132 132
133 133 def perfparents(ui, repo):
134 134 nl = [repo.changelog.node(i) for i in xrange(1000)]
135 135 def d():
136 136 for n in nl:
137 137 repo.changelog.parents(n)
138 138 timer(d)
139 139
140 140 def perflookup(ui, repo, rev):
141 141 timer(lambda: len(repo.lookup(rev)))
142 142
143 143 def perfrevrange(ui, repo, *specs):
144 144 revrange = scmutil.revrange
145 145 timer(lambda: len(revrange(repo, specs)))
146 146
147 147 def perfnodelookup(ui, repo, rev):
148 148 import mercurial.revlog
149 149 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
150 150 n = repo[rev].node()
151 151 def d():
152 152 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
153 153 cl.rev(n)
154 154 timer(d)
155 155
156 156 def perfnodelookup(ui, repo, rev):
157 157 import mercurial.revlog
158 158 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
159 159 n = repo[rev].node()
160 160 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
161 161 def d():
162 162 cl.rev(n)
163 163 clearcaches(cl)
164 164 timer(d)
165 165
166 166 def perflog(ui, repo, **opts):
167 167 ui.pushbuffer()
168 168 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
169 169 copies=opts.get('rename')))
170 170 ui.popbuffer()
171 171
172 172 def perftemplating(ui, repo):
173 173 ui.pushbuffer()
174 174 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
175 175 template='{date|shortdate} [{rev}:{node|short}]'
176 176 ' {author|person}: {desc|firstline}\n'))
177 177 ui.popbuffer()
178 178
179 179 def perfcca(ui, repo):
180 timer(lambda: scmutil.casecollisionauditor(ui, False, repo[None]))
180 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
181 181
182 182 def perffncacheload(ui, repo):
183 183 from mercurial import scmutil, store
184 184 s = store.store(set(['store','fncache']), repo.path, scmutil.opener)
185 185 def d():
186 186 s.fncache._load()
187 187 timer(d)
188 188
189 189 def perffncachewrite(ui, repo):
190 190 from mercurial import scmutil, store
191 191 s = store.store(set(['store','fncache']), repo.path, scmutil.opener)
192 192 s.fncache._load()
193 193 def d():
194 194 s.fncache._dirty = True
195 195 s.fncache.write()
196 196 timer(d)
197 197
198 198 def perfdiffwd(ui, repo):
199 199 """Profile diff of working directory changes"""
200 200 options = {
201 201 'w': 'ignore_all_space',
202 202 'b': 'ignore_space_change',
203 203 'B': 'ignore_blank_lines',
204 204 }
205 205
206 206 for diffopt in ('', 'w', 'b', 'B', 'wB'):
207 207 opts = dict((options[c], '1') for c in diffopt)
208 208 def d():
209 209 ui.pushbuffer()
210 210 commands.diff(ui, repo, **opts)
211 211 ui.popbuffer()
212 212 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
213 213 timer(d, title)
214 214
215 215 def perfrevlog(ui, repo, file_, **opts):
216 216 from mercurial import revlog
217 217 dist = opts['dist']
218 218 def d():
219 219 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
220 220 for x in xrange(0, len(r), dist):
221 221 r.revision(r.node(x))
222 222
223 223 timer(d)
224 224
225 225 cmdtable = {
226 226 'perfcca': (perfcca, []),
227 227 'perffncacheload': (perffncacheload, []),
228 228 'perffncachewrite': (perffncachewrite, []),
229 229 'perflookup': (perflookup, []),
230 230 'perfrevrange': (perfrevrange, []),
231 231 'perfnodelookup': (perfnodelookup, []),
232 232 'perfparents': (perfparents, []),
233 233 'perfstartup': (perfstartup, []),
234 234 'perfstatus': (perfstatus, []),
235 235 'perfwalk': (perfwalk, []),
236 236 'perfmanifest': (perfmanifest, []),
237 237 'perfchangeset': (perfchangeset, []),
238 238 'perfindex': (perfindex, []),
239 239 'perfheads': (perfheads, []),
240 240 'perftags': (perftags, []),
241 241 'perfancestors': (perfancestors, []),
242 242 'perfdirstate': (perfdirstate, []),
243 243 'perfdirstatedirs': (perfdirstate, []),
244 244 'perfdirstatewrite': (perfdirstatewrite, []),
245 245 'perflog': (perflog,
246 246 [('', 'rename', False, 'ask log to follow renames')]),
247 247 'perftemplating': (perftemplating, []),
248 248 'perfdiffwd': (perfdiffwd, []),
249 249 'perfrevlog': (perfrevlog,
250 250 [('d', 'dist', 100, 'distance between the revisions')],
251 251 "[INDEXFILE]"),
252 252 }
General Comments 0
You need to be logged in to leave comments. Login now