~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
 
27
27
 
28
28
class Benchmark(ExternalBase):
 
29
    """A Test class which provides helpers for writing benchmark tests."""
29
30
 
30
31
    def make_kernel_like_tree(self, url=None, root='.',
31
32
                              link_working=False):
32
33
        """Setup a temporary tree roughly like a kernel tree.
33
 
        
 
34
 
34
35
        :param url: Creat the kernel like tree as a lightweight checkout
35
 
        of a new branch created at url.
 
36
            of a new branch created at url.
 
37
        :param root: Path where the tree will be created.
36
38
        :param link_working: instead of creating a new copy of all files
37
39
            just hardlink the working tree. Tests must request this, because
38
40
            they must break links if they want to change the files
 
41
        :return: A newly created tree.
39
42
        """
40
43
        from bzrlib.benchmarks.tree_creator.kernel_like import (
41
44
            KernelLikeTreeCreator,
127
130
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
128
131
        return creator.create(root=directory_name)
129
132
 
130
 
    def create_with_commits(self, num_files, num_commits, directory_name='.'):
 
133
    def create_with_commits(self, num_files, num_commits, directory_name='.',
 
134
                            hardlink=False):
131
135
        """Create a tree with many files and many commits. Every commit changes
132
136
        exactly one file.
133
 
        
 
137
 
134
138
        :param num_files: number of files to be created
135
139
        :param num_commits: number of commits in the newly created tree
136
140
        """
137
 
        files = ["%s/%s" % (directory_name, i) for i in range(num_files)]
138
 
        for fn in files:
139
 
            f = open(fn, "wb")
140
 
            try:
141
 
                f.write("some content\n")
142
 
            finally:
143
 
                f.close()
144
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
145
 
        tree.add([str(i) for i in range(num_files)])
146
 
        tree.lock_write()
147
 
        try:
148
 
            tree.commit('initial commit')
149
 
            for i in range(num_commits):
150
 
                fn = files[i % len(files)]
151
 
                content = range(i) + [i, i, i, ""]
152
 
                f = open(fn, "wb")
153
 
                try:
154
 
                    f.write("\n".join([str(i) for i in content]))
155
 
                finally:
156
 
                    f.close()
157
 
                tree.commit("changing file %s" % fn)
158
 
        finally:
159
 
            tree.unlock()
 
141
        from bzrlib.benchmarks.tree_creator.many_commit import (
 
142
            ManyCommitTreeCreator,
 
143
            )
 
144
        creator = ManyCommitTreeCreator(self, link_bzr=hardlink,
 
145
                                        num_files=num_files,
 
146
                                        num_commits=num_commits)
 
147
        tree = creator.create(root=directory_name)
 
148
        files = ["%s/%s" % (directory_name, fn) for fn in creator.files]
160
149
        return tree, files
161
150
 
162
151
    def commit_some_revisions(self, tree, files, num_commits,
167
156
        :param tree: The tree in which the changes happen.
168
157
        :param files: The list of files where changes should occur.
169
158
        :param num_commits: The number of commits
170
 
        :param changes_per_commit: The number of files that are touched in 
171
 
        each commit.
 
159
        :param changes_per_commit: The number of files that are touched in
 
160
            each commit.
172
161
        """
173
162
        for j in range(num_commits):
174
163
            for i in range(changes_per_commit):
187
176
    testmod_names = [ \
188
177
                   'bzrlib.benchmarks.bench_add',
189
178
                   'bzrlib.benchmarks.bench_bench',
 
179
                   'bzrlib.benchmarks.bench_bundle',
190
180
                   'bzrlib.benchmarks.bench_cache_utf8',
191
181
                   'bzrlib.benchmarks.bench_checkout',
192
182
                   'bzrlib.benchmarks.bench_commit',
 
183
                   'bzrlib.benchmarks.bench_info',
193
184
                   'bzrlib.benchmarks.bench_inventory',
194
185
                   'bzrlib.benchmarks.bench_log',
195
186
                   'bzrlib.benchmarks.bench_osutils',
196
187
                   'bzrlib.benchmarks.bench_rocks',
 
188
                   'bzrlib.benchmarks.bench_startup',
197
189
                   'bzrlib.benchmarks.bench_status',
198
190
                   'bzrlib.benchmarks.bench_transform',
199
191
                   'bzrlib.benchmarks.bench_workingtree',