~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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
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
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
24
from bzrlib.benchmarks import Benchmark
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
25
from bzrlib.branch import Branch
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
26
from bzrlib.bundle.apply_bundle import install_bundle
2095.2.1 by John Arbash Meinel
Fix imports for bundles.
27
from bzrlib.bundle.serializer import read_bundle, write_bundle
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
28
from bzrlib.revision import NULL_REVISION
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
29
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
30
from bzrlib.workingtree import WorkingTree
31
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
32
33
class BundleBenchmark(Benchmark):
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
34
    """Benchmarks for bzr bundle performance and bzr merge with a bundle."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
35
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
36
    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
37
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
38
        or added and one commit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
39
        """
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
40
        self.make_kernel_like_committed_tree()
2644.2.1 by Lukáš Lalinský
Fix deprecation warnings on benchmarks.
41
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
42
43
    def test_create_bundle_many_commit_tree (self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
44
        """Create a bundle for a tree with many commits but no changes."""
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
45
        self.make_many_commit_tree()
2644.2.1 by Lukáš Lalinský
Fix deprecation warnings on benchmarks.
46
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
47
48
    def test_create_bundle_heavily_merged_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
49
        """Create a bundle for a heavily merged tree."""
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
50
        self.make_heavily_merged_tree()
2644.2.1 by Lukáš Lalinský
Fix deprecation warnings on benchmarks.
51
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
52
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
53
    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
54
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
55
        or added and one commit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
56
        """
1908.10.1 by Carl Friedrich Bolz
Fix make_kernel_like_tree_committed, which does not exist any more :-(.
57
        tree = self.make_kernel_like_committed_tree('tree')
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
58
59
        f = open('bundle', 'wb')
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
60
        try:
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
61
            write_bundle(tree.branch.repository, tree.last_revision(),
62
                         NULL_REVISION, f)
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
63
        finally:
64
            f.close()
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
65
66
        tree2 = self.make_branch_and_tree('branch_a')
67
        os.chdir('branch_a')
2644.2.1 by Lukáš Lalinský
Fix deprecation warnings on benchmarks.
68
        self.time(self.run_bzr, ['merge', '../bundle'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
69
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
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.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
75
        branch, relpath = Branch.open_containing("a")
1908.3.8 by holger krekel
Explicitely generate test functions.
76
        revision_history = branch.revision_history()
77
        bundle_text = StringIO()
78
        self.time(write_bundle, branch.repository, revision_history[-1],
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
79
                  NULL_REVISION, bundle_text)
1908.3.8 by holger krekel
Explicitely generate test functions.
80
        bundle_text.seek(0)
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
81
        target_tree = self.make_branch_and_tree('b')
82
        bundle = self.time(read_bundle, bundle_text)
83
        self.time(install_bundle, target_tree.branch.repository, bundle)
1908.3.8 by holger krekel
Explicitely generate test functions.
84
85
    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.
86
        os.mkdir("a")
87
        tree, files = self.create_with_commits(5, 1, directory_name="a")
88
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
89
        self._time_read_write()
90
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
91
    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.
92
        os.mkdir("a")
93
        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
94
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
95
        self._time_read_write()
96
97
    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.
98
        os.mkdir("a")
99
        tree, files = self.create_with_commits(100, 1, directory_name="a")
100
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
101
        self._time_read_write()
102
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
103
    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.
104
        os.mkdir("a")
105
        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
106
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
107
        self._time_read_write()
108
109
    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.
110
        os.mkdir("a")
111
        tree, files = self.create_with_commits(100, 1, directory_name="a")
112
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
113
        self._time_read_write()
114
115
    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.
116
        os.mkdir("a")
117
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
118
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
119
        self._time_read_write()
120
121
    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.
122
        os.mkdir("a")
123
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
124
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
125
        self._time_read_write()
126
127
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
128
class BundleLibraryLevelInstallBenchmark(Benchmark):
129
    """ Benchmarks for the install_bundle library function. """
130
131
    def _time_read_write(self):
132
        branch, relpath = Branch.open_containing("a")
133
        revision_history = branch.revision_history()
134
        bundle_text = StringIO()
135
        write_bundle(branch.repository, revision_history[-1],
136
                     NULL_REVISION, bundle_text)
137
        bundle_text.seek(0)
138
        target_tree = self.make_branch_and_tree('b')
139
        bundle = self.time(read_bundle, bundle_text)
140
        self.time(install_bundle, target_tree.branch.repository, bundle)
141
142
    def test_few_files_small_tree_1_revision(self):
143
        os.mkdir("a")
144
        tree, files = self.create_with_commits(5, 1, directory_name="a")
145
        self.commit_some_revisions(tree, files[:5], 1, 1)
146
        self._time_read_write()
147
148
    def test_few_files_small_tree_100_revision(self):
149
        os.mkdir("a")
150
        tree, files = self.create_with_commits(5, 1, directory_name="a")
151
        self.commit_some_revisions(tree, files[:5], 100, 1)
152
        self._time_read_write()
153
154
    def test_few_files_moderate_tree_1_revision(self):
155
        os.mkdir("a")
156
        tree, files = self.create_with_commits(100, 1, directory_name="a")
157
        self.commit_some_revisions(tree, files[:5], 1, 1)
158
        self._time_read_write()
159
160
    def test_few_files_moderate_tree_100_revision(self):
161
        os.mkdir("a")
162
        tree, files = self.create_with_commits(100, 1, directory_name="a")
163
        self.commit_some_revisions(tree, files[:5], 100, 1)
164
        self._time_read_write()
165
166
    def test_some_files_moderate_tree_1_revision(self):
167
        os.mkdir("a")
168
        tree, files = self.create_with_commits(100, 1, directory_name="a")
169
        self.commit_some_revisions(tree, files[:100], 1, 1)
170
        self._time_read_write()
171
172
    def test_few_files_big_tree_1_revision(self):
173
        os.mkdir("a")
174
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
175
        self.commit_some_revisions(tree, files[:5], 1, 1)
176
        self._time_read_write()
177
178
    def test_some_files_big_tree_1_revision(self):
179
        os.mkdir("a")
180
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
181
        self.commit_some_revisions(tree, files[:100], 1, 1)
182
        self._time_read_write()
183
1908.3.8 by holger krekel
Explicitely generate test functions.
184
185
if __name__ == '__main__':
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
186
    # USE the following if you want to regenerate the above test functions
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
187
    for treesize, treesize_h in [(5, "small"), (100, "moderate"),
188
                                 (1000, "big")]:
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
189
        for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some")]:
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
190
            if bundlefiles > treesize:
191
                continue
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
192
            for num_revisions in [1, 100]:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
193
                if (num_revisions >= 100 and
2097.1.3 by John Arbash Meinel
Skip the big-treex100 revision tests, which take 10min each
194
                        (bundlefiles >= 100 or treesize >= 1000)):
195
                    # Skip the 100x100x? tests.
196
                    # And the 100x?x1000
2097.1.2 by John Arbash Meinel
Skip the 100x100 bundle benchmarks
197
                    continue
1908.3.8 by holger krekel
Explicitely generate test functions.
198
                code = """\
199
    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.
200
        os.mkdir("a")
201
        tree, files = self.create_with_commits(%s, 1, directory_name="a")
202
        self.commit_some_revisions(tree, files[:%s], %s, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
203
        self._time_read_write()
204
""" % (bundlefiles_h, treesize_h, num_revisions,
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
205
       treesize, bundlefiles, num_revisions)
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
206
                print code
1908.8.3 by Carl Friedrich Bolz
(cfbolz, hpk): Add caching mechanism and add benchmark for bundle-reading.
207