~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

first cut at merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
"""Benchmark test suite for bzr."""
19
 
 
20
 
import bzrlib
21
 
from bzrlib.tests import TestLoader
22
 
from bzrlib.tests.blackbox import ExternalBase
23
 
 
24
 
class Benchmark(ExternalBase):
25
 
 
26
 
    def make_kernel_like_tree(self, url=None):
27
 
        """Setup a temporary tree roughly like a kernel tree.
28
 
        
29
 
        :param url: Creat the kernel like tree as a lightweight checkout
30
 
        of a new branch created at url.
31
 
        """
32
 
        # a kernel tree has ~10000 and 500 directory, with most files around 
33
 
        # 3-4 levels deep. 
34
 
        # we simulate this by three levels of dirs named 0-7, givin 512 dirs,
35
 
        # and 20 files each.
36
 
        if url is not None:
37
 
            b = bzrlib.bzrdir.BzrDir.create_branch_convenience(url)
38
 
            d = bzrlib.bzrdir.BzrDir.create('.')
39
 
            bzrlib.branch.BranchReferenceFormat().initialize(d, b)
40
 
            d.create_workingtree()
41
 
        else:
42
 
            self.run_bzr('init')
43
 
        files = []
44
 
        for outer in range(8):
45
 
            files.append("%s/" % outer)
46
 
            for middle in range(8):
47
 
                files.append("%s/%s/" % (outer, middle))
48
 
                for inner in range(8):
49
 
                    prefix = "%s/%s/%s/" % (outer, middle, inner)
50
 
                    files.append(prefix)
51
 
                    files.extend([prefix + str(foo) for foo in range(20)])
52
 
        self.build_tree(files)
53
 
 
54
 
 
55
 
def test_suite():
56
 
    """Build and return a TestSuite which contains benchmark tests only."""
57
 
    testmod_names = [ \
58
 
                   'bzrlib.benchmarks.bench_add',
59
 
                   'bzrlib.benchmarks.bench_bench',
60
 
                   'bzrlib.benchmarks.bench_checkout',
61
 
                   'bzrlib.benchmarks.bench_commit',
62
 
                   'bzrlib.benchmarks.bench_inventory',
63
 
                   'bzrlib.benchmarks.bench_osutils',
64
 
                   'bzrlib.benchmarks.bench_rocks',
65
 
                   'bzrlib.benchmarks.bench_status',
66
 
                   'bzrlib.benchmarks.bench_transform',
67
 
                   'bzrlib.benchmarks.bench_workingtree',
68
 
                   ]
69
 
    return TestLoader().loadTestsFromModuleNames(testmod_names)