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