~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
 
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
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.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()
79
        self.time(write_bundle, branch.repository, revision_history[-1],
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
80
                  NULL_REVISION, bundle_text)
1908.3.8 by holger krekel
Explicitely generate test functions.
81
        bundle_text.seek(0)
1908.3.15 by Carl Friedrich Bolz
Fix problems pointed out by John:
82
        target_tree = self.make_branch_and_tree('b')
83
        bundle = self.time(read_bundle, bundle_text)
84
        self.time(install_bundle, target_tree.branch.repository, bundle)
1908.3.8 by holger krekel
Explicitely generate test functions.
85
86
    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.
87
        os.mkdir("a")
88
        tree, files = self.create_with_commits(5, 1, directory_name="a")
89
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
90
        self._time_read_write()
91
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
92
    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.
93
        os.mkdir("a")
94
        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
95
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
96
        self._time_read_write()
97
98
    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.
99
        os.mkdir("a")
100
        tree, files = self.create_with_commits(100, 1, directory_name="a")
101
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
102
        self._time_read_write()
103
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
104
    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.
105
        os.mkdir("a")
106
        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
107
        self.commit_some_revisions(tree, files[:5], 100, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
108
        self._time_read_write()
109
110
    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.
111
        os.mkdir("a")
112
        tree, files = self.create_with_commits(100, 1, directory_name="a")
113
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
114
        self._time_read_write()
115
116
    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.
117
        os.mkdir("a")
118
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
119
        self.commit_some_revisions(tree, files[:5], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
120
        self._time_read_write()
121
122
    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.
123
        os.mkdir("a")
124
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
125
        self.commit_some_revisions(tree, files[:100], 1, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
126
        self._time_read_write()
127
128
1908.3.17 by Carl Friedrich Bolz
Fix bundle benchmarks: don't do install_bundle on too many revisions: takes way
129
class BundleLibraryLevelInstallBenchmark(Benchmark):
130
    """ Benchmarks for the install_bundle library function. """
131
132
    def _time_read_write(self):
133
        branch, relpath = Branch.open_containing("a")
134
        revision_history = branch.revision_history()
135
        bundle_text = StringIO()
136
        write_bundle(branch.repository, revision_history[-1],
137
                     NULL_REVISION, bundle_text)
138
        bundle_text.seek(0)
139
        target_tree = self.make_branch_and_tree('b')
140
        bundle = self.time(read_bundle, bundle_text)
141
        self.time(install_bundle, target_tree.branch.repository, bundle)
142
143
    def test_few_files_small_tree_1_revision(self):
144
        os.mkdir("a")
145
        tree, files = self.create_with_commits(5, 1, directory_name="a")
146
        self.commit_some_revisions(tree, files[:5], 1, 1)
147
        self._time_read_write()
148
149
    def test_few_files_small_tree_100_revision(self):
150
        os.mkdir("a")
151
        tree, files = self.create_with_commits(5, 1, directory_name="a")
152
        self.commit_some_revisions(tree, files[:5], 100, 1)
153
        self._time_read_write()
154
155
    def test_few_files_moderate_tree_1_revision(self):
156
        os.mkdir("a")
157
        tree, files = self.create_with_commits(100, 1, directory_name="a")
158
        self.commit_some_revisions(tree, files[:5], 1, 1)
159
        self._time_read_write()
160
161
    def test_few_files_moderate_tree_100_revision(self):
162
        os.mkdir("a")
163
        tree, files = self.create_with_commits(100, 1, directory_name="a")
164
        self.commit_some_revisions(tree, files[:5], 100, 1)
165
        self._time_read_write()
166
167
    def test_some_files_moderate_tree_1_revision(self):
168
        os.mkdir("a")
169
        tree, files = self.create_with_commits(100, 1, directory_name="a")
170
        self.commit_some_revisions(tree, files[:100], 1, 1)
171
        self._time_read_write()
172
173
    def test_few_files_big_tree_1_revision(self):
174
        os.mkdir("a")
175
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
176
        self.commit_some_revisions(tree, files[:5], 1, 1)
177
        self._time_read_write()
178
179
    def test_some_files_big_tree_1_revision(self):
180
        os.mkdir("a")
181
        tree, files = self.create_with_commits(1000, 1, directory_name="a")
182
        self.commit_some_revisions(tree, files[:100], 1, 1)
183
        self._time_read_write()
184
1908.3.8 by holger krekel
Explicitely generate test functions.
185
186
if __name__ == '__main__':
187
    # USE the following if you want to regenerate the above test functions 
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
188
    for treesize, treesize_h in [(5, "small"), (100, "moderate"),
189
                                 (1000, "big")]:
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
190
        for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some")]:
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
191
            if bundlefiles > treesize:
192
                continue
2097.1.1 by John Arbash Meinel
Don't run 1000 revision bundle tests
193
            for num_revisions in [1, 100]:
2097.1.3 by John Arbash Meinel
Skip the big-treex100 revision tests, which take 10min each
194
                if (num_revisions >= 100 and 
195
                        (bundlefiles >= 100 or treesize >= 1000)):
196
                    # Skip the 100x100x? tests.
197
                    # And the 100x?x1000
2097.1.2 by John Arbash Meinel
Skip the 100x100 bundle benchmarks
198
                    continue
1908.3.8 by holger krekel
Explicitely generate test functions.
199
                code = """\
200
    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.
201
        os.mkdir("a")
202
        tree, files = self.create_with_commits(%s, 1, directory_name="a")
203
        self.commit_some_revisions(tree, files[:%s], %s, 1)
1908.3.8 by holger krekel
Explicitely generate test functions.
204
        self._time_read_write()
205
""" % (bundlefiles_h, treesize_h, num_revisions,
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
206
       treesize, bundlefiles, num_revisions)
1908.3.12 by Carl Friedrich Bolz
Fix docstrings and other things to be PEP 8 compatible. Removed caching of
207
                print code
1908.8.3 by Carl Friedrich Bolz
(cfbolz, hpk): Add caching mechanism and add benchmark for bundle-reading.
208