16
16
"""Tests for bzr bundle performance."""
18
from cStringIO import StringIO
20
from cStringIO import StringIO
22
from bzrlib import bzrdir
22
23
from bzrlib.add import smart_add
23
from bzrlib import bzrdir
24
24
from bzrlib.benchmarks import Benchmark
25
25
from bzrlib.branch import Branch
26
26
from bzrlib.bundle import read_bundle
27
from bzrlib.bundle.apply_bundle import install_bundle
27
28
from bzrlib.bundle.serializer import write_bundle
29
from bzrlib.revision import NULL_REVISION
28
30
from bzrlib.revisionspec import RevisionSpec
29
31
from bzrlib.workingtree import WorkingTree
32
34
class BundleBenchmark(Benchmark):
33
"""The bundle tests should (also) be done at a lower level with
34
direct call to the bzrlib.
35
"""Benchmarks for bzr bundle performance and bzr merge with a bundle."""
37
def make_kernel_like_tree_committed(self):
38
self.make_kernel_like_added_tree()
39
self.run_bzr('commit', '-m', 'initial import')
41
37
def test_create_bundle_known_kernel_like_tree(self):
42
38
"""Create a bundle for a kernel sized tree with no ignored, unknowns,
43
39
or added and one commit.
59
55
"""Create a bundle for a kernel sized tree with no ignored, unknowns,
60
56
or added and one commit.
62
self.make_kernel_like_tree_committed()
63
f = file('../bundle', 'wb')
58
tree = self.make_kernel_like_tree_committed('tree')
60
f = open('bundle', 'wb')
65
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
62
write_bundle(tree.branch.repository, tree.last_revision(),
68
self.run_bzr("init", "../branch_a")
69
os.chdir('../branch_a')
67
tree2 = self.make_branch_and_tree('branch_a')
70
69
self.time(self.run_bzr, 'merge', '../bundle')
73
class BundleLibraryLevelBenchmark(Benchmark):
71
class BundleLibraryLevelWriteBenchmark(Benchmark):
72
""" Benchmarks for the write_bundle library function. """
75
74
def _time_read_write(self):
76
76
branch, relpath = Branch.open_containing("a")
77
77
revision_history = branch.revision_history()
78
78
bundle_text = StringIO()
79
print "starting write bundle"
79
80
self.time(write_bundle, branch.repository, revision_history[-1],
81
NULL_REVISION, bundle_text)
82
print "stopped writing bundle"
81
83
bundle_text.seek(0)
82
self.time(read_bundle, bundle_text)
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)
84
90
def test_few_files_small_tree_1_revision(self):