author | Matt Mackall <mpm@selenic.com> |
Wed, 03 Jun 2009 17:07:41 -0500 | |
changeset 8711 | 1b95c6f13155 |
parent 8656 | 284fda4cd093 |
child 8873 | e872ef2e6758 |
permissions | -rw-r--r-- |
7366
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 |
# perf.py - performance test routines |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 |
|
7872
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
3 |
from mercurial import cmdutil, match, commands |
7366
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 |
import time, os, sys |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 |
def timer(func): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
results = [] |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
8 |
begin = time.time() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 |
count = 0 |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
10 |
while 1: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
11 |
ostart = os.times() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 |
cstart = time.time() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 |
r = func() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 |
cstop = time.time() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 |
ostop = os.times() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 |
count += 1 |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 |
a, b = ostart, ostop |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
18 |
results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 |
if cstop - begin > 3 and count >= 100: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
20 |
break |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
21 |
if cstop - begin > 10 and count >= 3: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 |
break |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
23 |
if r: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
24 |
sys.stderr.write("! result: %s\n" % r) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
25 |
m = min(results) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
26 |
sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
27 |
% (m[0], m[1] + m[2], m[1], m[2], count)) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
28 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
29 |
def perfwalk(ui, repo, *pats): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
30 |
try: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
31 |
m = cmdutil.match(repo, pats, {}) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
32 |
timer(lambda: len(list(repo.dirstate.walk(m, True, False)))) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 |
except: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
34 |
try: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
35 |
m = cmdutil.match(repo, pats, {}) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
36 |
timer(lambda: len([b for a,b,c in repo.dirstate.statwalk([], m)])) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
37 |
except: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
38 |
timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
39 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
40 |
def perfstatus(ui, repo, *pats): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
41 |
#m = match.always(repo.root, repo.getcwd()) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
42 |
#timer(lambda: sum(map(len, repo.dirstate.status(m, False, False, False)))) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
43 |
timer(lambda: sum(map(len, repo.status()))) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
44 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
45 |
def perfheads(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 |
timer(lambda: len(repo.changelog.heads())) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
48 |
def perftags(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 |
import mercurial.changelog, mercurial.manifest |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 |
def t(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
51 |
repo.changelog = mercurial.changelog.changelog(repo.sopener) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
52 |
repo.manifest = mercurial.manifest.manifest(repo.sopener) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
53 |
repo.tagscache = None |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
54 |
return len(repo.tags()) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
55 |
timer(t) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 |
def perfdirstate(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
58 |
"a" in repo.dirstate |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
59 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
60 |
repo.dirstate.invalidate() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
61 |
"a" in repo.dirstate |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
62 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
64 |
def perfdirstatedirs(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
65 |
"a" in repo.dirstate |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
66 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
67 |
"a" in repo.dirstate._dirs |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
68 |
del repo.dirstate._dirs |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
69 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
70 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
71 |
def perfmanifest(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
72 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
73 |
t = repo.manifest.tip() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
74 |
m = repo.manifest.read(t) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
75 |
repo.manifest.mapcache = None |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
76 |
repo.manifest._cache = None |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
77 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
78 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
79 |
def perfindex(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
80 |
import mercurial.changelog |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
81 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
82 |
t = repo.changelog.tip() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
83 |
repo.changelog = mercurial.changelog.changelog(repo.sopener) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
84 |
repo.changelog._loadindexmap() |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
85 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
86 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
87 |
def perfstartup(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 |
cmd = sys.argv[0] |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
89 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
90 |
os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
91 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
93 |
def perfparents(ui, repo): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
94 |
nl = [repo.changelog.node(i) for i in xrange(1000)] |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
95 |
def d(): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
96 |
for n in nl: |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
97 |
repo.changelog.parents(n) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
98 |
timer(d) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
99 |
|
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
100 |
def perflookup(ui, repo, rev): |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
101 |
timer(lambda: len(repo.lookup(rev))) |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
102 |
|
7872
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
103 |
def perflog(ui, repo): |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
104 |
ui.pushbuffer() |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
105 |
timer(lambda: commands.log(ui, repo, rev=[], date='', user='')) |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
106 |
ui.popbuffer() |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
107 |
|
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
108 |
def perftemplating(ui, repo): |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
109 |
ui.pushbuffer() |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
110 |
timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
111 |
template='{date|shortdate} [{rev}:{node|short}]' |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
112 |
' {author|person}: {desc|firstline}\n')) |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
113 |
ui.popbuffer() |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
114 |
|
7366
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
115 |
cmdtable = { |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
116 |
'perflookup': (perflookup, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
117 |
'perfparents': (perfparents, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
118 |
'perfstartup': (perfstartup, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
119 |
'perfstatus': (perfstatus, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
120 |
'perfwalk': (perfwalk, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
121 |
'perfmanifest': (perfmanifest, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
122 |
'perfindex': (perfindex, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
123 |
'perfheads': (perfheads, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
124 |
'perftags': (perftags, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
125 |
'perfdirstate': (perfdirstate, []), |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
126 |
'perfdirstatedirs': (perfdirstate, []), |
7872
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
127 |
'perflog': (perflog, []), |
f680a1bd679b
contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7366
diff
changeset
|
128 |
'perftemplating': (perftemplating, []), |
7366
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
129 |
} |
eb240755386d
Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
130 |