1
# Copyright (C) 2006 by Canonical Ltd
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.
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.
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
18
"""Benchmark test suite for bzr."""
21
from bzrlib.bzrdir import BzrDir
22
from bzrlib.tests import TestLoader
23
from bzrlib.tests.blackbox import ExternalBase
25
class Benchmark(ExternalBase):
27
def make_kernel_like_tree(self, url=None):
28
"""Setup a temporary tree roughly like a kernel tree.
30
:param url: Creat the kernel like tree as a lightweight checkout
31
of a new branch created at url.
33
# a kernel tree has ~10000 and 500 directory, with most files around
35
# we simulate this by three levels of dirs named 0-7, givin 512 dirs,
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()
45
for outer in range(8):
46
files.append("%s/" % outer)
47
for middle in range(8):
48
files.append("%s/%s/" % (outer, middle))
49
for inner in range(8):
50
prefix = "%s/%s/%s/" % (outer, middle, inner)
52
files.extend([prefix + str(foo) for foo in range(20)])
53
self.build_tree(files)
55
def make_many_commit_tree(self, directory_name='.'):
56
"""Create a tree with an egregious number of commits.
58
No files change are included.
60
tree = BzrDir.create_standalone_workingtree(directory_name)
62
tree.branch.lock_write()
63
tree.branch.repository.lock_write()
65
for i in xrange(1000):
66
tree.commit('no-changes commit %d' % i)
70
tree.branch.repository.unlock()
79
"""Build and return a TestSuite which contains benchmark tests only."""
81
'bzrlib.benchmarks.bench_add',
82
'bzrlib.benchmarks.bench_bench',
83
'bzrlib.benchmarks.bench_checkout',
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',
89
'bzrlib.benchmarks.bench_status',
90
'bzrlib.benchmarks.bench_transform',
91
'bzrlib.benchmarks.bench_workingtree',
93
return TestLoader().loadTestsFromModuleNames(testmod_names)