##// END OF EJS Templates
perf: unroll the result in perfrevset...
Pierre-Yves David -
r20846:b581c582 default
parent child Browse files
Show More
@@ -1,424 +1,424 b''
1 # perf.py - performance test routines
1 # perf.py - performance test routines
2 '''helper extension to measure performance'''
2 '''helper extension to measure performance'''
3
3
4 from mercurial import cmdutil, scmutil, util, commands, obsolete
4 from mercurial import cmdutil, scmutil, util, commands, obsolete
5 from mercurial import repoview, branchmap, merge, copies
5 from mercurial import repoview, branchmap, merge, copies
6 import time, os, sys
6 import time, os, sys
7
7
8 cmdtable = {}
8 cmdtable = {}
9 command = cmdutil.command(cmdtable)
9 command = cmdutil.command(cmdtable)
10
10
11 def timer(func, title=None):
11 def timer(func, title=None):
12 results = []
12 results = []
13 begin = time.time()
13 begin = time.time()
14 count = 0
14 count = 0
15 while True:
15 while True:
16 ostart = os.times()
16 ostart = os.times()
17 cstart = time.time()
17 cstart = time.time()
18 r = func()
18 r = func()
19 cstop = time.time()
19 cstop = time.time()
20 ostop = os.times()
20 ostop = os.times()
21 count += 1
21 count += 1
22 a, b = ostart, ostop
22 a, b = ostart, ostop
23 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
23 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
24 if cstop - begin > 3 and count >= 100:
24 if cstop - begin > 3 and count >= 100:
25 break
25 break
26 if cstop - begin > 10 and count >= 3:
26 if cstop - begin > 10 and count >= 3:
27 break
27 break
28 if title:
28 if title:
29 sys.stderr.write("! %s\n" % title)
29 sys.stderr.write("! %s\n" % title)
30 if r:
30 if r:
31 sys.stderr.write("! result: %s\n" % r)
31 sys.stderr.write("! result: %s\n" % r)
32 m = min(results)
32 m = min(results)
33 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n"
33 sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n"
34 % (m[0], m[1] + m[2], m[1], m[2], count))
34 % (m[0], m[1] + m[2], m[1], m[2], count))
35
35
36 @command('perfwalk')
36 @command('perfwalk')
37 def perfwalk(ui, repo, *pats):
37 def perfwalk(ui, repo, *pats):
38 try:
38 try:
39 m = scmutil.match(repo[None], pats, {})
39 m = scmutil.match(repo[None], pats, {})
40 timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
40 timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
41 except Exception:
41 except Exception:
42 try:
42 try:
43 m = scmutil.match(repo[None], pats, {})
43 m = scmutil.match(repo[None], pats, {})
44 timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
44 timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
45 except Exception:
45 except Exception:
46 timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
46 timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
47
47
48 @command('perfannotate')
48 @command('perfannotate')
49 def perfannotate(ui, repo, f):
49 def perfannotate(ui, repo, f):
50 fc = repo['.'][f]
50 fc = repo['.'][f]
51 timer(lambda: len(fc.annotate(True)))
51 timer(lambda: len(fc.annotate(True)))
52
52
53 @command('perfstatus',
53 @command('perfstatus',
54 [('u', 'unknown', False,
54 [('u', 'unknown', False,
55 'ask status to look for unknown files')])
55 'ask status to look for unknown files')])
56 def perfstatus(ui, repo, **opts):
56 def perfstatus(ui, repo, **opts):
57 #m = match.always(repo.root, repo.getcwd())
57 #m = match.always(repo.root, repo.getcwd())
58 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
58 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
59 # False))))
59 # False))))
60 timer(lambda: sum(map(len, repo.status(**opts))))
60 timer(lambda: sum(map(len, repo.status(**opts))))
61
61
62 @command('perfaddremove')
62 @command('perfaddremove')
63 def perfaddremove(ui, repo):
63 def perfaddremove(ui, repo):
64 try:
64 try:
65 oldquiet = repo.ui.quiet
65 oldquiet = repo.ui.quiet
66 repo.ui.quiet = True
66 repo.ui.quiet = True
67 timer(lambda: scmutil.addremove(repo, dry_run=True))
67 timer(lambda: scmutil.addremove(repo, dry_run=True))
68 finally:
68 finally:
69 repo.ui.quiet = oldquiet
69 repo.ui.quiet = oldquiet
70
70
71 def clearcaches(cl):
71 def clearcaches(cl):
72 # behave somewhat consistently across internal API changes
72 # behave somewhat consistently across internal API changes
73 if util.safehasattr(cl, 'clearcaches'):
73 if util.safehasattr(cl, 'clearcaches'):
74 cl.clearcaches()
74 cl.clearcaches()
75 elif util.safehasattr(cl, '_nodecache'):
75 elif util.safehasattr(cl, '_nodecache'):
76 from mercurial.node import nullid, nullrev
76 from mercurial.node import nullid, nullrev
77 cl._nodecache = {nullid: nullrev}
77 cl._nodecache = {nullid: nullrev}
78 cl._nodepos = None
78 cl._nodepos = None
79
79
80 @command('perfheads')
80 @command('perfheads')
81 def perfheads(ui, repo):
81 def perfheads(ui, repo):
82 cl = repo.changelog
82 cl = repo.changelog
83 def d():
83 def d():
84 len(cl.headrevs())
84 len(cl.headrevs())
85 clearcaches(cl)
85 clearcaches(cl)
86 timer(d)
86 timer(d)
87
87
88 @command('perftags')
88 @command('perftags')
89 def perftags(ui, repo):
89 def perftags(ui, repo):
90 import mercurial.changelog
90 import mercurial.changelog
91 import mercurial.manifest
91 import mercurial.manifest
92 def t():
92 def t():
93 repo.changelog = mercurial.changelog.changelog(repo.sopener)
93 repo.changelog = mercurial.changelog.changelog(repo.sopener)
94 repo.manifest = mercurial.manifest.manifest(repo.sopener)
94 repo.manifest = mercurial.manifest.manifest(repo.sopener)
95 repo._tags = None
95 repo._tags = None
96 return len(repo.tags())
96 return len(repo.tags())
97 timer(t)
97 timer(t)
98
98
99 @command('perfancestors')
99 @command('perfancestors')
100 def perfancestors(ui, repo):
100 def perfancestors(ui, repo):
101 heads = repo.changelog.headrevs()
101 heads = repo.changelog.headrevs()
102 def d():
102 def d():
103 for a in repo.changelog.ancestors(heads):
103 for a in repo.changelog.ancestors(heads):
104 pass
104 pass
105 timer(d)
105 timer(d)
106
106
107 @command('perfancestorset')
107 @command('perfancestorset')
108 def perfancestorset(ui, repo, revset):
108 def perfancestorset(ui, repo, revset):
109 revs = repo.revs(revset)
109 revs = repo.revs(revset)
110 heads = repo.changelog.headrevs()
110 heads = repo.changelog.headrevs()
111 def d():
111 def d():
112 s = repo.changelog.ancestors(heads)
112 s = repo.changelog.ancestors(heads)
113 for rev in revs:
113 for rev in revs:
114 rev in s
114 rev in s
115 timer(d)
115 timer(d)
116
116
117 @command('perfdirs')
117 @command('perfdirs')
118 def perfdirs(ui, repo):
118 def perfdirs(ui, repo):
119 dirstate = repo.dirstate
119 dirstate = repo.dirstate
120 'a' in dirstate
120 'a' in dirstate
121 def d():
121 def d():
122 dirstate.dirs()
122 dirstate.dirs()
123 del dirstate._dirs
123 del dirstate._dirs
124 timer(d)
124 timer(d)
125
125
126 @command('perfdirstate')
126 @command('perfdirstate')
127 def perfdirstate(ui, repo):
127 def perfdirstate(ui, repo):
128 "a" in repo.dirstate
128 "a" in repo.dirstate
129 def d():
129 def d():
130 repo.dirstate.invalidate()
130 repo.dirstate.invalidate()
131 "a" in repo.dirstate
131 "a" in repo.dirstate
132 timer(d)
132 timer(d)
133
133
134 @command('perfdirstatedirs')
134 @command('perfdirstatedirs')
135 def perfdirstatedirs(ui, repo):
135 def perfdirstatedirs(ui, repo):
136 "a" in repo.dirstate
136 "a" in repo.dirstate
137 def d():
137 def d():
138 "a" in repo.dirstate._dirs
138 "a" in repo.dirstate._dirs
139 del repo.dirstate._dirs
139 del repo.dirstate._dirs
140 timer(d)
140 timer(d)
141
141
142 @command('perfdirstatewrite')
142 @command('perfdirstatewrite')
143 def perfdirstatewrite(ui, repo):
143 def perfdirstatewrite(ui, repo):
144 ds = repo.dirstate
144 ds = repo.dirstate
145 "a" in ds
145 "a" in ds
146 def d():
146 def d():
147 ds._dirty = True
147 ds._dirty = True
148 ds.write()
148 ds.write()
149 timer(d)
149 timer(d)
150
150
151 @command('perfmergecalculate',
151 @command('perfmergecalculate',
152 [('r', 'rev', '.', 'rev to merge against')])
152 [('r', 'rev', '.', 'rev to merge against')])
153 def perfmergecalculate(ui, repo, rev):
153 def perfmergecalculate(ui, repo, rev):
154 wctx = repo[None]
154 wctx = repo[None]
155 rctx = scmutil.revsingle(repo, rev, rev)
155 rctx = scmutil.revsingle(repo, rev, rev)
156 ancestor = wctx.ancestor(rctx)
156 ancestor = wctx.ancestor(rctx)
157 # we don't want working dir files to be stat'd in the benchmark, so prime
157 # we don't want working dir files to be stat'd in the benchmark, so prime
158 # that cache
158 # that cache
159 wctx.dirty()
159 wctx.dirty()
160 def d():
160 def d():
161 # acceptremote is True because we don't want prompts in the middle of
161 # acceptremote is True because we don't want prompts in the middle of
162 # our benchmark
162 # our benchmark
163 merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False,
163 merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False,
164 acceptremote=True)
164 acceptremote=True)
165 timer(d)
165 timer(d)
166
166
167 @command('perfpathcopies', [], "REV REV")
167 @command('perfpathcopies', [], "REV REV")
168 def perfpathcopies(ui, repo, rev1, rev2):
168 def perfpathcopies(ui, repo, rev1, rev2):
169 ctx1 = scmutil.revsingle(repo, rev1, rev1)
169 ctx1 = scmutil.revsingle(repo, rev1, rev1)
170 ctx2 = scmutil.revsingle(repo, rev2, rev2)
170 ctx2 = scmutil.revsingle(repo, rev2, rev2)
171 def d():
171 def d():
172 copies.pathcopies(ctx1, ctx2)
172 copies.pathcopies(ctx1, ctx2)
173 timer(d)
173 timer(d)
174
174
175 @command('perfmanifest', [], 'REV')
175 @command('perfmanifest', [], 'REV')
176 def perfmanifest(ui, repo, rev):
176 def perfmanifest(ui, repo, rev):
177 ctx = scmutil.revsingle(repo, rev, rev)
177 ctx = scmutil.revsingle(repo, rev, rev)
178 t = ctx.manifestnode()
178 t = ctx.manifestnode()
179 def d():
179 def d():
180 repo.manifest._mancache.clear()
180 repo.manifest._mancache.clear()
181 repo.manifest._cache = None
181 repo.manifest._cache = None
182 repo.manifest.read(t)
182 repo.manifest.read(t)
183 timer(d)
183 timer(d)
184
184
185 @command('perfchangeset')
185 @command('perfchangeset')
186 def perfchangeset(ui, repo, rev):
186 def perfchangeset(ui, repo, rev):
187 n = repo[rev].node()
187 n = repo[rev].node()
188 def d():
188 def d():
189 repo.changelog.read(n)
189 repo.changelog.read(n)
190 #repo.changelog._cache = None
190 #repo.changelog._cache = None
191 timer(d)
191 timer(d)
192
192
193 @command('perfindex')
193 @command('perfindex')
194 def perfindex(ui, repo):
194 def perfindex(ui, repo):
195 import mercurial.revlog
195 import mercurial.revlog
196 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
196 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
197 n = repo["tip"].node()
197 n = repo["tip"].node()
198 def d():
198 def d():
199 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
199 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
200 cl.rev(n)
200 cl.rev(n)
201 timer(d)
201 timer(d)
202
202
203 @command('perfstartup')
203 @command('perfstartup')
204 def perfstartup(ui, repo):
204 def perfstartup(ui, repo):
205 cmd = sys.argv[0]
205 cmd = sys.argv[0]
206 def d():
206 def d():
207 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
207 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
208 timer(d)
208 timer(d)
209
209
210 @command('perfparents')
210 @command('perfparents')
211 def perfparents(ui, repo):
211 def perfparents(ui, repo):
212 nl = [repo.changelog.node(i) for i in xrange(1000)]
212 nl = [repo.changelog.node(i) for i in xrange(1000)]
213 def d():
213 def d():
214 for n in nl:
214 for n in nl:
215 repo.changelog.parents(n)
215 repo.changelog.parents(n)
216 timer(d)
216 timer(d)
217
217
218 @command('perflookup')
218 @command('perflookup')
219 def perflookup(ui, repo, rev):
219 def perflookup(ui, repo, rev):
220 timer(lambda: len(repo.lookup(rev)))
220 timer(lambda: len(repo.lookup(rev)))
221
221
222 @command('perfrevrange')
222 @command('perfrevrange')
223 def perfrevrange(ui, repo, *specs):
223 def perfrevrange(ui, repo, *specs):
224 revrange = scmutil.revrange
224 revrange = scmutil.revrange
225 timer(lambda: len(revrange(repo, specs)))
225 timer(lambda: len(revrange(repo, specs)))
226
226
227 @command('perfnodelookup')
227 @command('perfnodelookup')
228 def perfnodelookup(ui, repo, rev):
228 def perfnodelookup(ui, repo, rev):
229 import mercurial.revlog
229 import mercurial.revlog
230 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
230 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
231 n = repo[rev].node()
231 n = repo[rev].node()
232 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
232 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
233 def d():
233 def d():
234 cl.rev(n)
234 cl.rev(n)
235 clearcaches(cl)
235 clearcaches(cl)
236 timer(d)
236 timer(d)
237
237
238 @command('perflog',
238 @command('perflog',
239 [('', 'rename', False, 'ask log to follow renames')])
239 [('', 'rename', False, 'ask log to follow renames')])
240 def perflog(ui, repo, **opts):
240 def perflog(ui, repo, **opts):
241 ui.pushbuffer()
241 ui.pushbuffer()
242 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
242 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
243 copies=opts.get('rename')))
243 copies=opts.get('rename')))
244 ui.popbuffer()
244 ui.popbuffer()
245
245
246 @command('perfmoonwalk')
246 @command('perfmoonwalk')
247 def perfmoonwalk(ui, repo):
247 def perfmoonwalk(ui, repo):
248 """benchmark walking the changelog backwards
248 """benchmark walking the changelog backwards
249
249
250 This also loads the changelog data for each revision in the changelog.
250 This also loads the changelog data for each revision in the changelog.
251 """
251 """
252 def moonwalk():
252 def moonwalk():
253 for i in xrange(len(repo), -1, -1):
253 for i in xrange(len(repo), -1, -1):
254 ctx = repo[i]
254 ctx = repo[i]
255 ctx.branch() # read changelog data (in addition to the index)
255 ctx.branch() # read changelog data (in addition to the index)
256 timer(moonwalk)
256 timer(moonwalk)
257
257
258 @command('perftemplating')
258 @command('perftemplating')
259 def perftemplating(ui, repo):
259 def perftemplating(ui, repo):
260 ui.pushbuffer()
260 ui.pushbuffer()
261 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
261 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
262 template='{date|shortdate} [{rev}:{node|short}]'
262 template='{date|shortdate} [{rev}:{node|short}]'
263 ' {author|person}: {desc|firstline}\n'))
263 ' {author|person}: {desc|firstline}\n'))
264 ui.popbuffer()
264 ui.popbuffer()
265
265
266 @command('perfcca')
266 @command('perfcca')
267 def perfcca(ui, repo):
267 def perfcca(ui, repo):
268 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
268 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
269
269
270 @command('perffncacheload')
270 @command('perffncacheload')
271 def perffncacheload(ui, repo):
271 def perffncacheload(ui, repo):
272 s = repo.store
272 s = repo.store
273 def d():
273 def d():
274 s.fncache._load()
274 s.fncache._load()
275 timer(d)
275 timer(d)
276
276
277 @command('perffncachewrite')
277 @command('perffncachewrite')
278 def perffncachewrite(ui, repo):
278 def perffncachewrite(ui, repo):
279 s = repo.store
279 s = repo.store
280 s.fncache._load()
280 s.fncache._load()
281 def d():
281 def d():
282 s.fncache._dirty = True
282 s.fncache._dirty = True
283 s.fncache.write()
283 s.fncache.write()
284 timer(d)
284 timer(d)
285
285
286 @command('perffncacheencode')
286 @command('perffncacheencode')
287 def perffncacheencode(ui, repo):
287 def perffncacheencode(ui, repo):
288 s = repo.store
288 s = repo.store
289 s.fncache._load()
289 s.fncache._load()
290 def d():
290 def d():
291 for p in s.fncache.entries:
291 for p in s.fncache.entries:
292 s.encode(p)
292 s.encode(p)
293 timer(d)
293 timer(d)
294
294
295 @command('perfdiffwd')
295 @command('perfdiffwd')
296 def perfdiffwd(ui, repo):
296 def perfdiffwd(ui, repo):
297 """Profile diff of working directory changes"""
297 """Profile diff of working directory changes"""
298 options = {
298 options = {
299 'w': 'ignore_all_space',
299 'w': 'ignore_all_space',
300 'b': 'ignore_space_change',
300 'b': 'ignore_space_change',
301 'B': 'ignore_blank_lines',
301 'B': 'ignore_blank_lines',
302 }
302 }
303
303
304 for diffopt in ('', 'w', 'b', 'B', 'wB'):
304 for diffopt in ('', 'w', 'b', 'B', 'wB'):
305 opts = dict((options[c], '1') for c in diffopt)
305 opts = dict((options[c], '1') for c in diffopt)
306 def d():
306 def d():
307 ui.pushbuffer()
307 ui.pushbuffer()
308 commands.diff(ui, repo, **opts)
308 commands.diff(ui, repo, **opts)
309 ui.popbuffer()
309 ui.popbuffer()
310 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
310 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
311 timer(d, title)
311 timer(d, title)
312
312
313 @command('perfrevlog',
313 @command('perfrevlog',
314 [('d', 'dist', 100, 'distance between the revisions')],
314 [('d', 'dist', 100, 'distance between the revisions')],
315 "[INDEXFILE]")
315 "[INDEXFILE]")
316 def perfrevlog(ui, repo, file_, **opts):
316 def perfrevlog(ui, repo, file_, **opts):
317 from mercurial import revlog
317 from mercurial import revlog
318 dist = opts['dist']
318 dist = opts['dist']
319 def d():
319 def d():
320 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
320 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
321 for x in xrange(0, len(r), dist):
321 for x in xrange(0, len(r), dist):
322 r.revision(r.node(x))
322 r.revision(r.node(x))
323
323
324 timer(d)
324 timer(d)
325
325
326 @command('perfrevset',
326 @command('perfrevset',
327 [('C', 'clear', False, 'clear volatile cache between each call.')],
327 [('C', 'clear', False, 'clear volatile cache between each call.')],
328 "REVSET")
328 "REVSET")
329 def perfrevset(ui, repo, expr, clear=False):
329 def perfrevset(ui, repo, expr, clear=False):
330 """benchmark the execution time of a revset
330 """benchmark the execution time of a revset
331
331
332 Use the --clean option if need to evaluate the impact of build volatile
332 Use the --clean option if need to evaluate the impact of build volatile
333 revisions set cache on the revset execution. Volatile cache hold filtered
333 revisions set cache on the revset execution. Volatile cache hold filtered
334 and obsolete related cache."""
334 and obsolete related cache."""
335 def d():
335 def d():
336 if clear:
336 if clear:
337 repo.invalidatevolatilesets()
337 repo.invalidatevolatilesets()
338 repo.revs(expr)
338 for r in repo.revs(expr): pass
339 timer(d)
339 timer(d)
340
340
341 @command('perfvolatilesets')
341 @command('perfvolatilesets')
342 def perfvolatilesets(ui, repo, *names):
342 def perfvolatilesets(ui, repo, *names):
343 """benchmark the computation of various volatile set
343 """benchmark the computation of various volatile set
344
344
345 Volatile set computes element related to filtering and obsolescence."""
345 Volatile set computes element related to filtering and obsolescence."""
346 repo = repo.unfiltered()
346 repo = repo.unfiltered()
347
347
348 def getobs(name):
348 def getobs(name):
349 def d():
349 def d():
350 repo.invalidatevolatilesets()
350 repo.invalidatevolatilesets()
351 obsolete.getrevs(repo, name)
351 obsolete.getrevs(repo, name)
352 return d
352 return d
353
353
354 allobs = sorted(obsolete.cachefuncs)
354 allobs = sorted(obsolete.cachefuncs)
355 if names:
355 if names:
356 allobs = [n for n in allobs if n in names]
356 allobs = [n for n in allobs if n in names]
357
357
358 for name in allobs:
358 for name in allobs:
359 timer(getobs(name), title=name)
359 timer(getobs(name), title=name)
360
360
361 def getfiltered(name):
361 def getfiltered(name):
362 def d():
362 def d():
363 repo.invalidatevolatilesets()
363 repo.invalidatevolatilesets()
364 repoview.filterrevs(repo, name)
364 repoview.filterrevs(repo, name)
365 return d
365 return d
366
366
367 allfilter = sorted(repoview.filtertable)
367 allfilter = sorted(repoview.filtertable)
368 if names:
368 if names:
369 allfilter = [n for n in allfilter if n in names]
369 allfilter = [n for n in allfilter if n in names]
370
370
371 for name in allfilter:
371 for name in allfilter:
372 timer(getfiltered(name), title=name)
372 timer(getfiltered(name), title=name)
373
373
374 @command('perfbranchmap',
374 @command('perfbranchmap',
375 [('f', 'full', False,
375 [('f', 'full', False,
376 'Includes build time of subset'),
376 'Includes build time of subset'),
377 ])
377 ])
378 def perfbranchmap(ui, repo, full=False):
378 def perfbranchmap(ui, repo, full=False):
379 """benchmark the update of a branchmap
379 """benchmark the update of a branchmap
380
380
381 This benchmarks the full repo.branchmap() call with read and write disabled
381 This benchmarks the full repo.branchmap() call with read and write disabled
382 """
382 """
383 def getbranchmap(filtername):
383 def getbranchmap(filtername):
384 """generate a benchmark function for the filtername"""
384 """generate a benchmark function for the filtername"""
385 if filtername is None:
385 if filtername is None:
386 view = repo
386 view = repo
387 else:
387 else:
388 view = repo.filtered(filtername)
388 view = repo.filtered(filtername)
389 def d():
389 def d():
390 if full:
390 if full:
391 view._branchcaches.clear()
391 view._branchcaches.clear()
392 else:
392 else:
393 view._branchcaches.pop(filtername, None)
393 view._branchcaches.pop(filtername, None)
394 view.branchmap()
394 view.branchmap()
395 return d
395 return d
396 # add filter in smaller subset to bigger subset
396 # add filter in smaller subset to bigger subset
397 possiblefilters = set(repoview.filtertable)
397 possiblefilters = set(repoview.filtertable)
398 allfilters = []
398 allfilters = []
399 while possiblefilters:
399 while possiblefilters:
400 for name in possiblefilters:
400 for name in possiblefilters:
401 subset = branchmap.subsettable.get(name)
401 subset = branchmap.subsettable.get(name)
402 if subset not in possiblefilters:
402 if subset not in possiblefilters:
403 break
403 break
404 else:
404 else:
405 assert False, 'subset cycle %s!' % possiblefilters
405 assert False, 'subset cycle %s!' % possiblefilters
406 allfilters.append(name)
406 allfilters.append(name)
407 possiblefilters.remove(name)
407 possiblefilters.remove(name)
408
408
409 # warm the cache
409 # warm the cache
410 if not full:
410 if not full:
411 for name in allfilters:
411 for name in allfilters:
412 repo.filtered(name).branchmap()
412 repo.filtered(name).branchmap()
413 # add unfiltered
413 # add unfiltered
414 allfilters.append(None)
414 allfilters.append(None)
415 oldread = branchmap.read
415 oldread = branchmap.read
416 oldwrite = branchmap.branchcache.write
416 oldwrite = branchmap.branchcache.write
417 try:
417 try:
418 branchmap.read = lambda repo: None
418 branchmap.read = lambda repo: None
419 branchmap.write = lambda repo: None
419 branchmap.write = lambda repo: None
420 for name in allfilters:
420 for name in allfilters:
421 timer(getbranchmap(name), title=str(name))
421 timer(getbranchmap(name), title=str(name))
422 finally:
422 finally:
423 branchmap.read = oldread
423 branchmap.read = oldread
424 branchmap.branchcache.write = oldwrite
424 branchmap.branchcache.write = oldwrite
General Comments 0
You need to be logged in to leave comments. Login now