~bzr-pqm/bzr/bzr.dev

2052.3.4 by John Arbash Meinel
[merge] bzr.dev
1
# Copyright (C) 2006 Canonical Ltd
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
2
#
3
# This program is free software; you can redistribute it and/or modify
2052.3.4 by John Arbash Meinel
[merge] bzr.dev
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for bzr bundle performance."""
18
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
19
from cStringIO import StringIO
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
20
import os
1908.8.3 by Carl Friedrich Bolz
(cfbolz, hpk): Add caching mechanism and add benchmark for bundle-reading.
21
import shutil
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
22
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
23
from bzrlib import bzrdir
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
24
from bzrlib.add import smart_add
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
25
from bzrlib.benchmarks import Benchmark
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
26
from bzrlib.branch import Branch
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
27
from bzrlib.bundle import read_bundle
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
28
from bzrlib.bundle.apply_bundle import install_bundle
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
29
from bzrlib.bundle.serializer import write_bundle
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
30
from bzrlib.revision import NULL_REVISION
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
31
from bzrlib.revisionspec import RevisionSpec
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
32
from bzrlib.workingtree import WorkingTree
33
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
34
35
class BundleBenchmark(Benchmark):
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
36
    """Benchmarks for bzr bundle performance and bzr merge with a bundle."""
1908.8.5 by holger krekel
route more creation code through cached_make
37
   
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
38
    def test_create_bundle_known_kernel_like_tree(self):
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
39
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
40
        or added and one commit.
41
        """ 
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
42
        self.make_kernel_like_committed_tree()
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
43
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
44
45
    def test_create_bundle_many_commit_tree (self):
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
46
        """Create a bundle for a tree with many commits but no changes.""" 
47
        self.make_many_commit_tree()
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
48
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
49
50
    def test_create_bundle_heavily_merged_tree(self):
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
51
        """Create a bundle for a heavily merged tree.""" 
52
        self.make_heavily_merged_tree()
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
53
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
54
        
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
55
    def test_apply_bundle_known_kernel_like_tree(self):
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
56
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
57
        or added and one commit.
58
        """ 
1908.10.1 by Carl Friedrich Bolz
Fix make_kernel_like_tree_committed, which does not exist any more :-(.
59
        tree = self.make_kernel_like_committed_tree('tree')
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
60
61
        f = open('bundle', 'wb')
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
62
        try:
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
63
            write_bundle(tree.branch.repository, tree.last_revision(),
64
                         NULL_REVISION, f)
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
65
        finally:
66
            f.close()
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
67
68
        tree2 = self.make_branch_and_tree('branch_a')
69
        os.chdir('branch_a')
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
70
        self.time(self.run_bzr, 'merge', '../bundle')
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
71
 
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
72
class BundleLibraryLevelWriteBenchmark(Benchmark):
73
    """ Benchmarks for the write_bundle library function. """
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
74
1908.3.8 by holger krekel
Explicitely generate test functions.
75
    def _time_read_write(self):
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
76
        print "timing"
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
77
        branch, relpath = Branch.open_containing("a")
1908.3.8 by holger krekel
Explicitely generate test functions.
78
        revision_history = branch.revision_history()
79
        bundle_text = StringIO()
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
80
        print "starting write bundle"
1908.3.8 by holger krekel
Explicitely generate test functions.
81
        self.time(write_bundle, branch.repository, revision_history[-1],
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
82
                  NULL_REVISION, bundle_text)
83
        print "stopped writing bundle"
1908.3.8 by holger krekel
Explicitely generate test functions.
84
        bundle_text.seek(0)
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
85
        target_tree = self.make_branch_and_tree('b')
86
        print "starting reading bundle"
87
        bundle = self.time(read_bundle, bundle_text)
88
        print "starting installing bundle"
89
        self.time(install_bundle, target_tree.branch.repository, bundle)
1908.3.8 by holger krekel
Explicitely generate test functions.
90
91
    def test_few_files_small_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
92
        os.mkdir("a")
93
        tree, files = self.create_with_commits(5, 1, directory_name="a")
94
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
95
        self._time_read_write()
96
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
97
    def test_few_files_small_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
98
        os.mkdir("a")
99
        tree, files = self.create_with_commits(5, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
100
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
101
        self._time_read_write()
102
103
    def test_few_files_small_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
104
        os.mkdir("a")
105
        tree, files = self.create_with_commits(5, 1, directory_name="a")
106
        self.commit_some_revisions(tree, files[:5], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
107
        self._time_read_write()
108
109
    def test_few_files_moderate_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
110
        os.mkdir("a")
111
        tree, files = self.create_with_commits(100, 1, directory_name="a")
112
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
113
        self._time_read_write()
114
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
115
    def test_few_files_moderate_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
116
        os.mkdir("a")
117
        tree, files = self.create_with_commits(100, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
118
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
119
        self._time_read_write()
120
121
    def test_few_files_moderate_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
122
        os.mkdir("a")
123
        tree, files = self.create_with_commits(100, 1, directory_name="a")
124
        self.commit_some_revisions(tree, files[:5], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
125
        self._time_read_write()
126
127
    def test_some_files_moderate_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
128
        os.mkdir("a")
129
        tree, files = self.create_with_commits(100, 1, directory_name="a")
130
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
131
        self._time_read_write()
132
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
133
    def test_some_files_moderate_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
134
        os.mkdir("a")
135
        tree, files = self.create_with_commits(100, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
136
        self.commit_some_revisions(tree, files[:100], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
137
        self._time_read_write()
138
139
    def test_some_files_moderate_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
140
        os.mkdir("a")
141
        tree, files = self.create_with_commits(100, 1, directory_name="a")
142
        self.commit_some_revisions(tree, files[:100], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
143
        self._time_read_write()
144
145
    def test_few_files_big_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
146
        os.mkdir("a")
147
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
148
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
149
        self._time_read_write()
150
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
151
    def test_few_files_big_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
152
        os.mkdir("a")
153
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
154
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
155
        self._time_read_write()
156
157
    def test_few_files_big_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
158
        os.mkdir("a")
159
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
160
        self.commit_some_revisions(tree, files[:5], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
161
        self._time_read_write()
162
163
    def test_some_files_big_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
164
        os.mkdir("a")
165
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
166
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
167
        self._time_read_write()
168
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
169
    def test_some_files_big_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
170
        os.mkdir("a")
171
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
172
        self.commit_some_revisions(tree, files[:100], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
173
        self._time_read_write()
174
175
    def test_some_files_big_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
176
        os.mkdir("a")
177
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
178
        self.commit_some_revisions(tree, files[:100], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
179
        self._time_read_write()
180
181
    def test_many_files_big_tree_1_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
182
        os.mkdir("a")
183
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
184
        self.commit_some_revisions(tree, files[:1000], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
185
        self._time_read_write()
186
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
187
    def test_many_files_big_tree_100_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
188
        os.mkdir("a")
189
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
190
        self.commit_some_revisions(tree, files[:1000], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
191
        self._time_read_write()
192
193
    def test_many_files_big_tree_1000_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
194
        os.mkdir("a")
195
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
196
        self.commit_some_revisions(tree, files[:1000], 1000, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
197
        self._time_read_write()
198
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
199
class BundleLibraryLevelInstallBenchmark(Benchmark):
200
    """ Benchmarks for the install_bundle library function. """
201
202
    def _time_read_write(self):
203
        branch, relpath = Branch.open_containing("a")
204
        revision_history = branch.revision_history()
205
        bundle_text = StringIO()
206
        write_bundle(branch.repository, revision_history[-1],
207
                     NULL_REVISION, bundle_text)
208
        bundle_text.seek(0)
209
        target_tree = self.make_branch_and_tree('b')
210
        bundle = self.time(read_bundle, bundle_text)
211
        self.time(install_bundle, target_tree.branch.repository, bundle)
212
213
    def test_few_files_small_tree_1_revision(self):
214
        os.mkdir("a")
215
        tree, files = self.create_with_commits(5, 1, directory_name="a")
216
        self.commit_some_revisions(tree, files[:5], 1, 1)
217
        self._time_read_write()
218
219
    def test_few_files_small_tree_100_revision(self):
220
        os.mkdir("a")
221
        tree, files = self.create_with_commits(5, 1, directory_name="a")
222
        self.commit_some_revisions(tree, files[:5], 100, 1)
223
        self._time_read_write()
224
225
    def test_few_files_moderate_tree_1_revision(self):
226
        os.mkdir("a")
227
        tree, files = self.create_with_commits(100, 1, directory_name="a")
228
        self.commit_some_revisions(tree, files[:5], 1, 1)
229
        self._time_read_write()
230
231
    def test_few_files_moderate_tree_100_revision(self):
232
        os.mkdir("a")
233
        tree, files = self.create_with_commits(100, 1, directory_name="a")
234
        self.commit_some_revisions(tree, files[:5], 100, 1)
235
        self._time_read_write()
236
237
    def test_some_files_moderate_tree_1_revision(self):
238
        os.mkdir("a")
239
        tree, files = self.create_with_commits(100, 1, directory_name="a")
240
        self.commit_some_revisions(tree, files[:100], 1, 1)
241
        self._time_read_write()
242
243
    def test_some_files_moderate_tree_100_revision(self):
244
        os.mkdir("a")
245
        tree, files = self.create_with_commits(100, 1, directory_name="a")
246
        self.commit_some_revisions(tree, files[:100], 100, 1)
247
        self._time_read_write()
248
249
    def test_few_files_big_tree_1_revision(self):
250
        os.mkdir("a")
251
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
252
        self.commit_some_revisions(tree, files[:5], 1, 1)
253
        self._time_read_write()
254
255
    def test_few_files_big_tree_100_revision(self):
256
        os.mkdir("a")
257
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
258
        self.commit_some_revisions(tree, files[:5], 100, 1)
259
        self._time_read_write()
260
261
    def test_some_files_big_tree_1_revision(self):
262
        os.mkdir("a")
263
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
264
        self.commit_some_revisions(tree, files[:100], 1, 1)
265
        self._time_read_write()
266
267
    def test_some_files_big_tree_100_revision(self):
268
        os.mkdir("a")
269
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
270
        self.commit_some_revisions(tree, files[:100], 100, 1)
271
        self._time_read_write()
272
273
    def test_many_files_big_tree_1_revision(self):
274
        os.mkdir("a")
275
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
276
        self.commit_some_revisions(tree, files[:1000], 1, 1)
277
        self._time_read_write()
278
279
    def test_many_files_big_tree_100_revision(self):
280
        os.mkdir("a")
281
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
282
        self.commit_some_revisions(tree, files[:1000], 100, 1)
283
        self._time_read_write()
284
1908.3.8 by holger krekel
Explicitely generate test functions.
285
286
if __name__ == '__main__':
287
    # USE the following if you want to regenerate the above test functions 
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
288
    for treesize, treesize_h in [(5, "small"), (100, "moderate"),
289
                                 (1000, "big")]:
290
        for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some"),
291
                                           (1000, "many")]:
292
            if bundlefiles > treesize:
293
                continue
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
294
            for num_revisions in [1, 100, 1000]:
1908.3.8 by holger krekel
Explicitely generate test functions.
295
                code = """\
296
    def test_%s_files_%s_tree_%s_revision(self):
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
297
        os.mkdir("a")
298
        tree, files = self.create_with_commits(%s, 1, directory_name="a")
299
        self.commit_some_revisions(tree, files[:%s], %s, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
300
        self._time_read_write()
301
""" % (bundlefiles_h, treesize_h, num_revisions,
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
302
       treesize, bundlefiles, num_revisions)
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
303
                print code
1908.8.3 by Carl Friedrich Bolz
(cfbolz, hpk): Add caching mechanism and add benchmark for bundle-reading.
304
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
305
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
306