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