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