annotate contrib/sillybench.py @ 794:41bb6ec2ca27

Propagate c36a6f534b99 Fix named branching book section. 'hg update -C branchname' is no longer required to jump from one named branch to another one; this can also be done simply using 'hg update branchname'.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 18 Jun 2009 16:23:58 +0900
parents 2180358c32c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
222
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
1 #!/usr/bin/python
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2 #
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
3 # Silly benchmarking program, to give a vague idea of how fast a few
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4 # tools are on a handful of common operations.
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5 #
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 # Use a fairly big and real source tarball to test with: Firefox
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7 # 2.0.0.3 (37622 files, 5374 directories, 343MB unpacked onto
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8 # 4KB-blocksize ext3).
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10 import csv
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 import os
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12 import shutil
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13 import sys
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14 import tempfile
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 import time
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
16 import urllib2
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
18 url = 'ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.3/source/firefox-2.0.0.3-source.tar.bz2'
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
19
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 class CommandFailure(Exception):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
22
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
23 class rcs(object):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
24 def __init__(self):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25 self.logfp = open(self.__class__.__name__ + '.csv', 'w')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 self.csv = csv.writer(self.logfp)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
27
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28 def download(self):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29 name = url[url.rfind('/')+1:]
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30 path = os.path.join(os.environ['HOME'], name)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 if not os.path.isfile(path):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
32 ofp = open(path + '.part', 'wb')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33 try:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34 ifp = urllib2.urlopen(url)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35 nbytes = ifp.info()['content-length']
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 sys.stdout.write('%s: %s bytes ' % (name, nbytes))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
37 sys.stdout.flush()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 while True:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39 data = ifp.read(131072)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 if not data: break
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41 sys.stdout.write('.')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42 sys.stdout.flush()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43 ofp.write(data)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44 del ofp
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 os.rename(path + '.part', path)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46 except:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 if os.path.exists(path + '.part'):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 os.unlink(path + '.part')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 if os.path.exists(path):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50 os.unlink(path)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 raise
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52 return path
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54 def run(self, args, mustsucceed=True):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
55 ret = os.spawnvp(os.P_WAIT, args[0], args)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 if ret < 0:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57 msg = 'killed by signal %d' % (-ret)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 if ret > 0:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 msg = 'exited with status %d' % (ret)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60 if ret:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61 if mustsucceed:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
62 raise CommandFailure('%s: %s' % (msg, ' '.join(args)))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
63 print >> sys.stderr, 'WARNING: %s: %s' % (msg, ' '.join(args))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
64
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
65 def time(self, *args, **kwargs):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
66 start = time.time()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
67 self.run(*args, **kwargs)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
68 end = time.time()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
69 return end - start
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
70
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
71 def logtime(self, name, elapsed, rest=[]):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
72 self.log('time:' + name, '%.3f' % elapsed, rest)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
73
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
74 def log(self, name, value, rest=[]):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
75 item = (name, value, repr(rest))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
76 print ' '.join(item)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
77 self.csv.writerow(item)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
78 self.logfp.flush()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
79
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
80 def unpack(self):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
81 tarball = self.download()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
82 t = self.time(['tar', '-C', self.wdir, '-jxf', tarball])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
83 self.logtime('internal:untar', t)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
84 for name in os.listdir(os.path.join(self.wdir, 'mozilla')):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
85 os.rename(os.path.join(self.wdir, 'mozilla', name),
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
86 os.path.join(self.wdir, name))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
87
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
88 def cleanup(self):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
89 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
90
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
91 def add(self, paths):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
92 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
93
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
94 def commit(self, msg, paths):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
95 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
96
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
97 def status(self, path):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
98 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
99
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
100 def remove(self, path):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
101 pass
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
102
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
103
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
104 class subversion(rcs):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
105 def __init__(self, root):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
106 rcs.__init__(self)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
107 self.repo = os.path.join(root, 'repo')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
108 self.wdir = os.path.join(root, 'wc')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
109 create = self.time(['svnadmin', 'create', '--fs-type=fsfs', self.repo])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
110 self.logtime('svn:create', create)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
111 co = self.time(['svn', 'co', 'file://' + self.repo, self.wdir])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
112 self.logtime('svn:co', co)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
113 self.logtime('init', create + co)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
114 os.chdir(self.wdir)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
115
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
116 def dropmeta(self, names):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
117 return [n for n in names if os.path.basename(n) != '.svn']
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
118
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
119 def add(self, paths):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
120 t = self.time(['svn', 'add', '-q'] + paths)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
121 self.logtime('add %r' % paths, t)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
122
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
123 def commit(self, msg, paths=[]):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
124 if paths:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
125 t = self.time(['svn', 'ci', '-q', '-m', msg] + paths)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
126 else:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
127 t = self.time(['svn', 'ci', '-q', '-m', msg])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
128 self.logtime('commit %r' % paths, t)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
129
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
130
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
131 class mercurial(rcs):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
132 def __init__(self, root):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
133 rcs.__init__(self)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
134 self.repo = os.path.join(root, 'repo')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
135 self.wdir = self.repo
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
136 init = self.time(['hg', 'init', self.repo])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
137 self.logtime('init', init)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
138 os.chdir(self.wdir)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
139
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
140 def dropmeta(self, names):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
141 return [n for n in names if os.path.basename(n) != '.hg']
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
142
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
143 def add(self, paths):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
144 t = self.time(['hg', 'add', '-q'] + paths)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
145 self.logtime('add %r' % paths, t)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
146
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
147 def commit(self, msg, paths=[]):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
148 if paths:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
149 t = self.time(['hg', 'ci', '-q', '-m', msg] + paths)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
150 else:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
151 t = self.time(['hg', 'ci', '-q', '-m', msg])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
152 self.logtime('commit %r' % paths, t)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
153
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
154 def benchmark(cls):
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
155 oldcwd = os.getcwd()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
156 root = tempfile.mkdtemp(prefix='sillybench.')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
157 try:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
158 print 'root', root
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
159 inst = cls(root)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
160 inst.unpack()
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
161 names = inst.dropmeta(os.listdir('.'))
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
162 dirs = [n for n in names if os.path.isdir(n)]
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
163 nondirs = [n for n in names if not os.path.isdir(n)]
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
164 dirs.sort(key=hash)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
165 names.sort(key=hash)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
166 for d in dirs[:len(dirs)/2]:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
167 inst.add([d])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
168 inst.commit('Add %r' % d, [d])
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
169 inst.add(dirs[len(dirs)/2:] + names)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
170 inst.commit('Add remaining dirs and files')
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
171 finally:
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
172 print >> sys.stderr, '[cleaning up...]'
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
173 shutil.rmtree(root)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
174 os.chdir(oldcwd)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
175
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
176 benchmark(mercurial)
b2b593eb56e7 Add sillybench script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
177 #benchmark(subversion)