1
# Copyright (C) 2006 Canonical Ltd
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.
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.
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
17
"""Tests for bzr bundle performance."""
19
from cStringIO import StringIO
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
33
class BundleBenchmark(Benchmark):
34
"""Benchmarks for bzr bundle performance and bzr merge with a bundle."""
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.
40
self.make_kernel_like_committed_tree()
41
self.time(self.run_bzr, ['bundle', '--revision', '..-1'])
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'])
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'])
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.
57
tree = self.make_kernel_like_committed_tree('tree')
59
f = open('bundle', 'wb')
61
write_bundle(tree.branch.repository, tree.last_revision(),
66
tree2 = self.make_branch_and_tree('branch_a')
68
self.time(self.run_bzr, ['merge', '../bundle'])
71
class BundleLibraryLevelWriteBenchmark(Benchmark):
72
""" Benchmarks for the write_bundle library function. """
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)
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)
85
def test_few_files_small_tree_1_revision(self):
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()
91
def test_few_files_small_tree_100_revision(self):
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()
97
def test_few_files_moderate_tree_1_revision(self):
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()
103
def test_few_files_moderate_tree_100_revision(self):
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()
109
def test_some_files_moderate_tree_1_revision(self):
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()
115
def test_few_files_big_tree_1_revision(self):
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()
121
def test_some_files_big_tree_1_revision(self):
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()
128
class BundleLibraryLevelInstallBenchmark(Benchmark):
129
""" Benchmarks for the install_bundle library function. """
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)
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)
142
def test_few_files_small_tree_1_revision(self):
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()
148
def test_few_files_small_tree_100_revision(self):
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()
154
def test_few_files_moderate_tree_1_revision(self):
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()
160
def test_few_files_moderate_tree_100_revision(self):
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()
166
def test_some_files_moderate_tree_1_revision(self):
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()
172
def test_few_files_big_tree_1_revision(self):
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()
178
def test_some_files_big_tree_1_revision(self):
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()
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"),
189
for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some")]:
190
if bundlefiles > treesize:
192
for num_revisions in [1, 100]:
193
if (num_revisions >= 100 and
194
(bundlefiles >= 100 or treesize >= 1000)):
195
# Skip the 100x100x? tests.
199
def test_%s_files_%s_tree_%s_revision(self):
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)