1
# Copyright (C) 2007 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
17
"""Benchmarks for bzr DirState performance."""
29
class BenchmarkDirState(benchmarks.Benchmark):
31
def build_20k_dirstate(self):
32
"""Build a DirState file with 20k records.
34
This approximates a kernel tree, based on the number of directories
35
(1000), and number of files per directory (20) and depth (3).
36
Because DirState doesn't have to have actual disk records, we just add
38
We try to have reasonable filename lengths, as well as a reasonable
41
self.build_tree(['dir/'])
42
self.build_tree_contents([('file', 'x'*10000)])
43
file_stat = os.lstat('file')
44
dir_stat = os.lstat('dir')
45
file_sha1 = osutils.sha_string('testing')
47
# the average filename length is 11 characters
48
# find . | sed -e 's/.*\///' | wc -l
50
# 237869 / 22545 = 10.6
51
# average depth is 30 characters
54
# 679884 / 22545 = 30.1
55
state = dirstate.DirState.initialize('state')
57
for lvl1 in xrange(10):
58
dir_1 = '%2d_directory' % (lvl1,)
59
dir_1_id = generate_ids.gen_file_id(dir_1)
60
state.add(dir_1, dir_1_id, 'directory', dir_stat, '')
61
for lvl2 in xrange(10):
62
dir_2 = '%s/%2d_directory' % (dir_1, lvl2)
63
dir_2_id = generate_ids.gen_file_id(dir_2)
64
state.add(dir_2, dir_2_id, 'directory', dir_stat, '')
65
for lvl3 in xrange(10):
66
dir_3 = '%s/%2d_directory' % (dir_2, lvl3)
67
dir_3_id = generate_ids.gen_file_id(dir_3)
68
state.add(dir_3, dir_3_id, 'directory', dir_stat, '')
69
for filenum in xrange(20):
70
fname = '%s/%2d_filename' % (dir_3, filenum)
71
file_id = generate_ids.gen_file_id(fname)
72
state.add(fname, file_id, 'directory', dir_stat, '')
78
def test_build_20k_dirblocks(self):
79
state = self.time(self.build_20k_dirstate)
82
entries = list(state._iter_entries())
83
self.assertEqual(21111, len(entries))
87
def test__read_dirblocks_20k_tree_no_parents(self):
88
state = self.build_20k_dirstate()
91
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
92
state._dirblock_state)
93
self.time(state._read_dirblocks_if_needed)