/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
1
# Copyright (C) 2006 by 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 version 2 as published by
5
# the Free Software Foundation.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
"""Tests for bzr bundle performance."""
17
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
18
19
import os
20
from StringIO import StringIO
21
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
22
from bzrlib.benchmarks import Benchmark
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
23
from bzrlib.workingtree import WorkingTree
24
from bzrlib.branch import Branch
25
from bzrlib.bundle.serializer import write_bundle
26
from bzrlib.revisionspec import RevisionSpec
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
27
28
29
class BundleBenchmark(Benchmark):
30
    """
31
    The bundle tests should (also) be done at a lower level with
32
    direct call to the bzrlib."""
33
    
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
34
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
35
    def test_create_bundle_known_kernel_like_tree(self):
36
        """
37
        Create a bundle for a kernel sized tree with no ignored, unknowns,
38
        or added and one commit.""" 
39
        self.make_kernel_like_tree()
40
        self.run_bzr('add')
41
        self.run_bzr('commit', '-m', 'initial import')
42
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
43
44
    def test_create_bundle_many_commit_tree (self):
45
        """
46
        Create a bundle for a tree with many commits but no changes.""" 
47
        self.make_many_commit_tree()
48
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
49
50
    def test_create_bundle_heavily_merged_tree(self):
51
        """
52
        Create a bundle for a heavily merged tree.""" 
53
        self.make_heavily_merged_tree()
54
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
55
        
1908.3.3 by Carl Friedrich Bolz
Add benchmark for applying a benchmark and fix some formatting/typos.
56
    def test_apply_bundle_known_kernel_like_tree(self):
57
        """
58
        Create a bundle for a kernel sized tree with no ignored, unknowns,
59
        or added and one commit.""" 
60
        self.make_kernel_like_tree()
61
        self.run_bzr('add')
62
        self.run_bzr('commit', '-m', 'initial import')
63
        self.run_bzr('branch', '.', '../branch_a')
64
        self.run_bzr('bundle', '--revision', '..-1')
65
        f = file('../bundle', 'wb')
66
        try:
67
            f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
68
        finally:
69
            f.close()
70
        os.chdir('../branch_a')
71
        self.time(self.run_bzr, 'merge', '../bundle')
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
72
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
73
 
1908.8.1 by Carl Friedrich Bolz
low level bundle tests.
74
class BundleLibraryLevelBenchmark(Benchmark):
75
76
    def make_parametrized_tree(self, num_files, num_revisions,
77
                               num_files_in_bundle):
78
        """Create a tree with given parameters. Always creates 2 levels of
79
        directories with the given number of files. Then the given number of
80
        revisions are created, changing some lines in one files in each
81
        revision. Only num_files_in_bundle files are changed in these
82
        revisions.
83
84
        :param num_files: number of files in tree
85
        :param num_revisions: number of revisions
86
        :param num_files_in_bundle: number of files changed in the revisions
87
        """
88
        # create files
89
        directories = []
90
        files = []
91
        count = 0
92
        for outer in range(num_files // 64 + 1):
93
            directories.append("%s/" % outer)
94
            for middle in range(8):
95
                prefix = "%s/%s/" % (outer, middle)
96
                directories.append(prefix)
97
                for filename in range(min(8, num_files - count)):
98
                    count += 1
99
                    files.append(prefix + str(filename))
100
        self.run_bzr('init')
101
        self.build_tree(directories + files)
102
        for d in directories:
103
            self.run_bzr('add', d)
104
        self.run_bzr('commit', '-m', 'initial repo layout')
105
        # create revisions
106
        affected_files = files[:num_files_in_bundle]
107
        count = 0
108
        for changes_file in range(num_revisions // num_files_in_bundle + 1):
109
            for f in affected_files:
110
                count += 1
111
                if count >= num_revisions:
112
                    break
113
                content = "\n".join([str(i) for i in range(changes_file)] +
114
                                    [str(changes_file)] * 5) + "\n"
115
                self.build_tree_contents([(f, content)])
116
                self.run_bzr("commit", '-m', 'some changes')
117
        assert count >= num_revisions
118
119
    for treesize, treesize_h in [(5, "small"), (100, "moderate"),
120
                                 (1000, "big")]:
121
        for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some"),
122
                                           (1000, "many")]:
123
            if bundlefiles > treesize:
124
                continue
125
            for num_revisions in [1, 500, 1000]:
126
                code = """
127
def test_%s_files_%s_tree_%s_revision(self):
128
    self.make_parametrized_tree(%s, %s, %s)
129
    branch, _ = Branch.open_containing(".")
130
    revision_history = branch.revision_history()
131
    bundle_text = StringIO()
132
    self.time(write_bundle, branch.repository, revision_history[-1],
133
              None, bundle_text)""" % (
134
                    bundlefiles_h, treesize_h, num_revisions,
135
                    treesize, num_revisions, bundlefiles)
136
              #exec code