~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Benchmark test suite for bzr."""
19
19
 
20
 
from bzrlib.tests import TestLoader
 
20
import bzrlib
 
21
from bzrlib.tests.TestUtil import TestLoader
 
22
from bzrlib.bzrdir import BzrDir
21
23
from bzrlib.tests.blackbox import ExternalBase
22
24
 
23
25
class Benchmark(ExternalBase):
24
26
 
25
 
    def make_kernel_like_tree(self):
26
 
        """Setup a temporary tree roughly like a kernel tree."""
 
27
    def make_kernel_like_tree(self, url=None):
 
28
        """Setup a temporary tree roughly like a kernel tree.
 
29
        
 
30
        :param url: Creat the kernel like tree as a lightweight checkout
 
31
        of a new branch created at url.
 
32
        """
27
33
        # a kernel tree has ~10000 and 500 directory, with most files around 
28
34
        # 3-4 levels deep. 
29
35
        # we simulate this by three levels of dirs named 0-7, givin 512 dirs,
30
36
        # and 20 files each.
31
 
        self.run_bzr('init')
 
37
        if url is not None:
 
38
            b = bzrlib.bzrdir.BzrDir.create_branch_convenience(url)
 
39
            d = bzrlib.bzrdir.BzrDir.create('.')
 
40
            bzrlib.branch.BranchReferenceFormat().initialize(d, b)
 
41
            d.create_workingtree()
 
42
        else:
 
43
            self.run_bzr('init')
32
44
        files = []
33
45
        for outer in range(8):
34
46
            files.append("%s/" % outer)
40
52
                    files.extend([prefix + str(foo) for foo in range(20)])
41
53
        self.build_tree(files)
42
54
 
 
55
    def make_many_commit_tree(self, directory_name='.'):
 
56
        """Create a tree with an egregious number of commits.
 
57
        
 
58
        No files change are included.
 
59
        """
 
60
        tree = BzrDir.create_standalone_workingtree(directory_name)
 
61
        tree.lock_write()
 
62
        tree.branch.lock_write()
 
63
        tree.branch.repository.lock_write()
 
64
        try:
 
65
            for i in xrange(1000):
 
66
                tree.commit('no-changes commit %d' % i)
 
67
        finally:
 
68
            try:
 
69
                try:
 
70
                    tree.branch.repository.unlock()
 
71
                finally:
 
72
                    tree.branch.unlock()
 
73
            finally:
 
74
                tree.unlock()
 
75
        return tree
 
76
 
43
77
 
44
78
def test_suite():
45
79
    """Build and return a TestSuite which contains benchmark tests only."""
46
80
    testmod_names = [ \
47
81
                   'bzrlib.benchmarks.bench_add',
 
82
                   'bzrlib.benchmarks.bench_bench',
48
83
                   'bzrlib.benchmarks.bench_checkout',
49
84
                   'bzrlib.benchmarks.bench_commit',
 
85
                   'bzrlib.benchmarks.bench_inventory',
 
86
                   'bzrlib.benchmarks.bench_log',
 
87
                   'bzrlib.benchmarks.bench_osutils',
 
88
                   'bzrlib.benchmarks.bench_rocks',
50
89
                   'bzrlib.benchmarks.bench_status',
51
90
                   'bzrlib.benchmarks.bench_transform',
52
91
                   'bzrlib.benchmarks.bench_workingtree',