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