~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-13 09:29:44 UTC
  • mfrom: (4738.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091013092944-37m2zia1k83g061y
(vila) Clearer thread leaks reports

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
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.
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for bzr bundle performance."""
 
18
 
 
19
from cStringIO import StringIO
 
20
import os
 
21
import shutil
 
22
 
 
23
from bzrlib import bzrdir
 
24
from bzrlib.benchmarks import Benchmark
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.bundle.apply_bundle import install_bundle
 
27
from bzrlib.bundle.serializer import read_bundle, write_bundle
 
28
from bzrlib.revision import NULL_REVISION
 
29
from bzrlib.revisionspec import RevisionSpec
 
30
from bzrlib.workingtree import WorkingTree
 
31
 
 
32
 
 
33
class BundleBenchmark(Benchmark):
 
34
    """Benchmarks for bzr bundle performance and bzr merge with a bundle."""
 
35
 
 
36
    def test_create_bundle_known_kernel_like_tree(self):
 
37
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
 
38
        or added and one commit.
 
39
        """
 
40
        self.make_kernel_like_committed_tree()
 
41
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
 
42
 
 
43
    def test_create_bundle_many_commit_tree (self):
 
44
        """Create a bundle for a tree with many commits but no changes."""
 
45
        self.make_many_commit_tree()
 
46
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
 
47
 
 
48
    def test_create_bundle_heavily_merged_tree(self):
 
49
        """Create a bundle for a heavily merged tree."""
 
50
        self.make_heavily_merged_tree()
 
51
        self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
 
52
 
 
53
    def test_apply_bundle_known_kernel_like_tree(self):
 
54
        """Create a bundle for a kernel sized tree with no ignored, unknowns,
 
55
        or added and one commit.
 
56
        """
 
57
        tree = self.make_kernel_like_committed_tree('tree')
 
58
 
 
59
        f = open('bundle', 'wb')
 
60
        try:
 
61
            write_bundle(tree.branch.repository, tree.last_revision(),
 
62
                         NULL_REVISION, f)
 
63
        finally:
 
64
            f.close()
 
65
 
 
66
        tree2 = self.make_branch_and_tree('branch_a')
 
67
        os.chdir('branch_a')
 
68
        self.time(self.run_bzr, ['merge', '../bundle'])
 
69
 
 
70
 
 
71
class BundleLibraryLevelWriteBenchmark(Benchmark):
 
72
    """ Benchmarks for the write_bundle library function. """
 
73
 
 
74
    def _time_read_write(self):
 
75
        branch, relpath = Branch.open_containing("a")
 
76
        revision_history = branch.revision_history()
 
77
        bundle_text = StringIO()
 
78
        self.time(write_bundle, branch.repository, revision_history[-1],
 
79
                  NULL_REVISION, bundle_text)
 
80
        bundle_text.seek(0)
 
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)
 
84
 
 
85
    def test_few_files_small_tree_1_revision(self):
 
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)
 
89
        self._time_read_write()
 
90
 
 
91
    def test_few_files_small_tree_100_revision(self):
 
92
        os.mkdir("a")
 
93
        tree, files = self.create_with_commits(5, 1, directory_name="a")
 
94
        self.commit_some_revisions(tree, files[:5], 100, 1)
 
95
        self._time_read_write()
 
96
 
 
97
    def test_few_files_moderate_tree_1_revision(self):
 
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)
 
101
        self._time_read_write()
 
102
 
 
103
    def test_few_files_moderate_tree_100_revision(self):
 
104
        os.mkdir("a")
 
105
        tree, files = self.create_with_commits(100, 1, directory_name="a")
 
106
        self.commit_some_revisions(tree, files[:5], 100, 1)
 
107
        self._time_read_write()
 
108
 
 
109
    def test_some_files_moderate_tree_1_revision(self):
 
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)
 
113
        self._time_read_write()
 
114
 
 
115
    def test_few_files_big_tree_1_revision(self):
 
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)
 
119
        self._time_read_write()
 
120
 
 
121
    def test_some_files_big_tree_1_revision(self):
 
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)
 
125
        self._time_read_write()
 
126
 
 
127
 
 
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
 
 
184
 
 
185
if __name__ == '__main__':
 
186
    # USE the following if you want to regenerate the above test functions
 
187
    for treesize, treesize_h in [(5, "small"), (100, "moderate"),
 
188
                                 (1000, "big")]:
 
189
        for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some")]:
 
190
            if bundlefiles > treesize:
 
191
                continue
 
192
            for num_revisions in [1, 100]:
 
193
                if (num_revisions >= 100 and
 
194
                        (bundlefiles >= 100 or treesize >= 1000)):
 
195
                    # Skip the 100x100x? tests.
 
196
                    # And the 100x?x1000
 
197
                    continue
 
198
                code = """\
 
199
    def test_%s_files_%s_tree_%s_revision(self):
 
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)
 
203
        self._time_read_write()
 
204
""" % (bundlefiles_h, treesize_h, num_revisions,
 
205
       treesize, bundlefiles, num_revisions)
 
206
                print code
 
207