~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-18 22:52:19 UTC
  • mfrom: (1711.2.134 sftp-benchmarks)
  • mto: This revision was merged to the branch mainline in revision 1989.
  • Revision ID: john@arbash-meinel.com-20060818225219-6f4bfa3870d716b7
[merge] sftp benchmarks

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Benchmark test suite for bzr."""
18
18
 
19
19
from bzrlib import (
 
20
    bzrdir,
20
21
    plugin,
21
22
    )
 
23
import bzrlib.branch
22
24
from bzrlib.tests.TestUtil import TestLoader
23
25
from bzrlib.tests.blackbox import ExternalBase
24
26
 
125
127
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
126
128
        return creator.create(root=directory_name)
127
129
 
 
130
    def create_with_commits(self, num_files, num_commits, directory_name='.'):
 
131
        """Create a tree with many files and many commits. Every commit changes
 
132
        exactly one file.
 
133
        
 
134
        :param num_files: number of files to be created
 
135
        :param num_commits: number of commits in the newly created tree
 
136
        """
 
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()
 
160
        return tree, files
 
161
 
 
162
    def commit_some_revisions(self, tree, files, num_commits,
 
163
                              changes_per_commit):
 
164
        """Commit a specified number of revisions to some files in a tree,
 
165
        makeing a specified number of changes per commit.
 
166
 
 
167
        :param tree: The tree in which the changes happen.
 
168
        :param files: The list of files where changes should occur.
 
169
        :param num_commits: The number of commits
 
170
        :param changes_per_commit: The number of files that are touched in 
 
171
        each commit.
 
172
        """
 
173
        for j in range(num_commits):
 
174
            for i in range(changes_per_commit):
 
175
                fn = files[(i + j) % changes_per_commit]
 
176
                content = range(i) + [i, i, i, '']
 
177
                f = open(fn, "w")
 
178
                try:
 
179
                    f.write("\n".join([str(k) for k in content]))
 
180
                finally:
 
181
                    f.close()
 
182
            tree.commit("new revision")
 
183
 
128
184
 
129
185
def test_suite():
130
186
    """Build and return a TestSuite which contains benchmark tests only."""
141
197
                   'bzrlib.benchmarks.bench_status',
142
198
                   'bzrlib.benchmarks.bench_transform',
143
199
                   'bzrlib.benchmarks.bench_workingtree',
 
200
                   'bzrlib.benchmarks.bench_sftp',
144
201
                   'bzrlib.benchmarks.bench_xml',
145
202
                   ]
146
203
    suite = TestLoader().loadTestsFromModuleNames(testmod_names)