##// END OF EJS Templates
perf: tweak tests for testing index performance improvements
Matt Mackall -
r16260:33fcad3c default
parent child Browse files
Show More
@@ -1,166 +1,166
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, match, commands
4 from mercurial import cmdutil, scmutil, 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:
36 except:
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:
40 except:
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, False))))
45 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, False))))
46 timer(lambda: sum(map(len, repo.status())))
46 timer(lambda: sum(map(len, repo.status())))
47
47
48 def perfheads(ui, repo):
48 def perfheads(ui, repo):
49 timer(lambda: len(repo.changelog.heads()))
49 timer(lambda: len(repo.changelog.headrevs()))
50
50
51 def perftags(ui, repo):
51 def perftags(ui, repo):
52 import mercurial.changelog, mercurial.manifest
52 import mercurial.changelog, mercurial.manifest
53 def t():
53 def t():
54 repo.changelog = mercurial.changelog.changelog(repo.sopener)
54 repo.changelog = mercurial.changelog.changelog(repo.sopener)
55 repo.manifest = mercurial.manifest.manifest(repo.sopener)
55 repo.manifest = mercurial.manifest.manifest(repo.sopener)
56 repo._tags = None
56 repo._tags = None
57 return len(repo.tags())
57 return len(repo.tags())
58 timer(t)
58 timer(t)
59
59
60 def perfdirstate(ui, repo):
60 def perfdirstate(ui, repo):
61 "a" in repo.dirstate
61 "a" in repo.dirstate
62 def d():
62 def d():
63 repo.dirstate.invalidate()
63 repo.dirstate.invalidate()
64 "a" in repo.dirstate
64 "a" in repo.dirstate
65 timer(d)
65 timer(d)
66
66
67 def perfdirstatedirs(ui, repo):
67 def perfdirstatedirs(ui, repo):
68 "a" in repo.dirstate
68 "a" in repo.dirstate
69 def d():
69 def d():
70 "a" in repo.dirstate._dirs
70 "a" in repo.dirstate._dirs
71 del repo.dirstate._dirs
71 del repo.dirstate._dirs
72 timer(d)
72 timer(d)
73
73
74 def perfmanifest(ui, repo):
74 def perfmanifest(ui, repo):
75 def d():
75 def d():
76 t = repo.manifest.tip()
76 t = repo.manifest.tip()
77 m = repo.manifest.read(t)
77 m = repo.manifest.read(t)
78 repo.manifest.mapcache = None
78 repo.manifest.mapcache = None
79 repo.manifest._cache = None
79 repo.manifest._cache = None
80 timer(d)
80 timer(d)
81
81
82 def perfindex(ui, repo):
82 def perfindex(ui, repo):
83 import mercurial.revlog
83 import mercurial.revlog
84 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
84 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
85 n = repo["tip"].node()
85 n = repo["tip"].node()
86 def d():
86 def d():
87 repo.invalidate()
87 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
88 repo[n]
88 cl.rev(n)
89 timer(d)
89 timer(d)
90
90
91 def perfstartup(ui, repo):
91 def perfstartup(ui, repo):
92 cmd = sys.argv[0]
92 cmd = sys.argv[0]
93 def d():
93 def d():
94 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
94 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
95 timer(d)
95 timer(d)
96
96
97 def perfparents(ui, repo):
97 def perfparents(ui, repo):
98 nl = [repo.changelog.node(i) for i in xrange(1000)]
98 nl = [repo.changelog.node(i) for i in xrange(1000)]
99 def d():
99 def d():
100 for n in nl:
100 for n in nl:
101 repo.changelog.parents(n)
101 repo.changelog.parents(n)
102 timer(d)
102 timer(d)
103
103
104 def perflookup(ui, repo, rev):
104 def perflookup(ui, repo, rev):
105 timer(lambda: len(repo.lookup(rev)))
105 timer(lambda: len(repo.lookup(rev)))
106
106
107 def perflog(ui, repo, **opts):
107 def perflog(ui, repo, **opts):
108 ui.pushbuffer()
108 ui.pushbuffer()
109 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
109 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
110 copies=opts.get('rename')))
110 copies=opts.get('rename')))
111 ui.popbuffer()
111 ui.popbuffer()
112
112
113 def perftemplating(ui, repo):
113 def perftemplating(ui, repo):
114 ui.pushbuffer()
114 ui.pushbuffer()
115 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
115 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
116 template='{date|shortdate} [{rev}:{node|short}]'
116 template='{date|shortdate} [{rev}:{node|short}]'
117 ' {author|person}: {desc|firstline}\n'))
117 ' {author|person}: {desc|firstline}\n'))
118 ui.popbuffer()
118 ui.popbuffer()
119
119
120 def perfdiffwd(ui, repo):
120 def perfdiffwd(ui, repo):
121 """Profile diff of working directory changes"""
121 """Profile diff of working directory changes"""
122 options = {
122 options = {
123 'w': 'ignore_all_space',
123 'w': 'ignore_all_space',
124 'b': 'ignore_space_change',
124 'b': 'ignore_space_change',
125 'B': 'ignore_blank_lines',
125 'B': 'ignore_blank_lines',
126 }
126 }
127
127
128 for diffopt in ('', 'w', 'b', 'B', 'wB'):
128 for diffopt in ('', 'w', 'b', 'B', 'wB'):
129 opts = dict((options[c], '1') for c in diffopt)
129 opts = dict((options[c], '1') for c in diffopt)
130 def d():
130 def d():
131 ui.pushbuffer()
131 ui.pushbuffer()
132 commands.diff(ui, repo, **opts)
132 commands.diff(ui, repo, **opts)
133 ui.popbuffer()
133 ui.popbuffer()
134 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
134 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
135 timer(d, title)
135 timer(d, title)
136
136
137 def perfrevlog(ui, repo, file_, **opts):
137 def perfrevlog(ui, repo, file_, **opts):
138 from mercurial import revlog
138 from mercurial import revlog
139 dist = opts['dist']
139 dist = opts['dist']
140 def d():
140 def d():
141 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
141 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
142 for x in xrange(0, len(r), dist):
142 for x in xrange(0, len(r), dist):
143 r.revision(r.node(x))
143 r.revision(r.node(x))
144
144
145 timer(d)
145 timer(d)
146
146
147 cmdtable = {
147 cmdtable = {
148 'perflookup': (perflookup, []),
148 'perflookup': (perflookup, []),
149 'perfparents': (perfparents, []),
149 'perfparents': (perfparents, []),
150 'perfstartup': (perfstartup, []),
150 'perfstartup': (perfstartup, []),
151 'perfstatus': (perfstatus, []),
151 'perfstatus': (perfstatus, []),
152 'perfwalk': (perfwalk, []),
152 'perfwalk': (perfwalk, []),
153 'perfmanifest': (perfmanifest, []),
153 'perfmanifest': (perfmanifest, []),
154 'perfindex': (perfindex, []),
154 'perfindex': (perfindex, []),
155 'perfheads': (perfheads, []),
155 'perfheads': (perfheads, []),
156 'perftags': (perftags, []),
156 'perftags': (perftags, []),
157 'perfdirstate': (perfdirstate, []),
157 'perfdirstate': (perfdirstate, []),
158 'perfdirstatedirs': (perfdirstate, []),
158 'perfdirstatedirs': (perfdirstate, []),
159 'perflog': (perflog,
159 'perflog': (perflog,
160 [('', 'rename', False, 'ask log to follow renames')]),
160 [('', 'rename', False, 'ask log to follow renames')]),
161 'perftemplating': (perftemplating, []),
161 'perftemplating': (perftemplating, []),
162 'perfdiffwd': (perfdiffwd, []),
162 'perfdiffwd': (perfdiffwd, []),
163 'perfrevlog': (perfrevlog,
163 'perfrevlog': (perfrevlog,
164 [('d', 'dist', 100, 'distance between the revisions')],
164 [('d', 'dist', 100, 'distance between the revisions')],
165 "[INDEXFILE]"),
165 "[INDEXFILE]"),
166 }
166 }
General Comments 0
You need to be logged in to leave comments. Login now