~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

Late bind to PatienceSequenceMatcher to allow plugin to override.

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 import bzrdir, plugin
21
 
from bzrlib.tests.TestUtil import TestLoader
 
20
from bzrlib.tests import TestLoader
22
21
from bzrlib.tests.blackbox import ExternalBase
23
22
 
24
 
 
25
23
class Benchmark(ExternalBase):
26
24
 
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
 
        """
 
25
    def make_kernel_like_tree(self):
 
26
        """Setup a temporary tree roughly like a kernel tree."""
33
27
        # a kernel tree has ~10000 and 500 directory, with most files around 
34
28
        # 3-4 levels deep. 
35
29
        # we simulate this by three levels of dirs named 0-7, givin 512 dirs,
36
30
        # and 20 files each.
37
 
        if url is not None:
38
 
            b = bzrdir.BzrDir.create_branch_convenience(url)
39
 
            d = bzrdir.BzrDir.create('.')
40
 
            bzrlib.branch.BranchReferenceFormat().initialize(d, b)
41
 
            d.create_workingtree()
42
 
        else:
43
 
            self.run_bzr('init')
 
31
        self.run_bzr('init')
44
32
        files = []
45
33
        for outer in range(8):
46
34
            files.append("%s/" % outer)
52
40
                    files.extend([prefix + str(foo) for foo in range(20)])
53
41
        self.build_tree(files)
54
42
 
55
 
    def make_many_commit_tree(self, directory_name='.'):
56
 
        """Create a tree with many commits.
57
 
        
58
 
        No files change are included.
59
 
        """
60
 
        tree = bzrdir.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
 
 
77
 
    def make_heavily_merged_tree(self, directory_name='.'):
78
 
        """Create a tree in which almost every commit is a merge.
79
 
       
80
 
        No files change are included.  This produces two trees, 
81
 
        one of which is returned.  Except for the first commit, every
82
 
        commit in its revision-history is a merge another commit in the other
83
 
        tree.
84
 
        """
85
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
86
 
        tree.lock_write()
87
 
        try:
88
 
            tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
89
 
            tree2.lock_write()
90
 
            try:
91
 
                for i in xrange(250):
92
 
                    revision_id = tree.commit('no-changes commit %d-a' % i)
93
 
                    tree2.branch.fetch(tree.branch, revision_id)
94
 
                    tree2.set_pending_merges([revision_id])
95
 
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
96
 
                    tree.branch.fetch(tree2.branch, revision_id)
97
 
                    tree.set_pending_merges([revision_id])
98
 
                tree.set_pending_merges([])
99
 
            finally:
100
 
                tree.unlock()
101
 
        finally:
102
 
            tree2.unlock()
103
 
        return tree
104
 
 
105
43
 
106
44
def test_suite():
107
45
    """Build and return a TestSuite which contains benchmark tests only."""
108
46
    testmod_names = [ \
109
47
                   'bzrlib.benchmarks.bench_add',
110
 
                   'bzrlib.benchmarks.bench_bench',
111
48
                   'bzrlib.benchmarks.bench_checkout',
112
49
                   'bzrlib.benchmarks.bench_commit',
113
 
                   'bzrlib.benchmarks.bench_inventory',
114
 
                   'bzrlib.benchmarks.bench_log',
115
 
                   'bzrlib.benchmarks.bench_osutils',
116
 
                   'bzrlib.benchmarks.bench_rocks',
117
50
                   'bzrlib.benchmarks.bench_status',
118
51
                   'bzrlib.benchmarks.bench_transform',
119
 
                   'bzrlib.benchmarks.bench_workingtree',
120
52
                   ]
121
 
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
122
 
 
123
 
    # Load any benchmarks from plugins
124
 
    for name, module in plugin.all_plugins().items():
125
 
        if getattr(module, 'bench_suite', None) is not None:
126
 
            suite.addTest(module.bench_suite())
127
 
 
128
 
    return suite
 
53
    return TestLoader().loadTestsFromModuleNames(testmod_names)