182
182
self.checkOffsets(offsets)
186
def create_path_names(self, layout, base=''):
187
"""Create a list of paths with auto-generated names.
189
:param layout: A list of [(num_dirs, num_files)] tuples. For each
190
level, the given number of directories will be created, each
191
containing that many files.
192
So [(2, 5), (3, 4)] will create 2 top level directories, containing
193
5 files, and each top level directory will contain 3 subdirs with 4
195
:param base: The base path to prepend to all entries, most callers will
197
:return: A list of path names.
203
num_dirs, num_files = layout[0]
204
for dnum in xrange(num_dirs):
206
path = '%s/%02d_directory' % (base, dnum)
208
path = '%02d_directory' % (dnum,)
210
for fnum in xrange(num_files):
211
fname = '%s/%02d_filename' % (path, fnum)
213
paths.extend(self.create_path_names(layout[1:], base=path))
216
def test_create_path_names(self):
217
names = self.create_path_names([(2, 3), (1, 2)])
218
self.assertEqual(['00_directory',
219
'00_directory/00_filename',
220
'00_directory/01_filename',
221
'00_directory/02_filename',
222
'00_directory/00_directory',
223
'00_directory/00_directory/00_filename',
224
'00_directory/00_directory/01_filename',
226
'01_directory/00_filename',
227
'01_directory/01_filename',
228
'01_directory/02_filename',
229
'01_directory/00_directory',
230
'01_directory/00_directory/00_filename',
231
'01_directory/00_directory/01_filename',
233
names = self.time(self.create_path_names, [(10, 2), (10, 2), (10, 20)])
234
# 20 files + 1 directory name, 10 times, plus 2 filenames and 1 dir, 10
235
# times, and another 2 files + 1 dir, 10 times
236
self.assertEqual(21330, 10*(3 + 10*(3 + 10*(1 + 20))))
237
self.assertEqual(21330, len(names))
239
def compareAllPaths(self, cmp_func, layout):
240
"""Compare N^2 paths.
242
Basically, compare every path in the list against every other path.
244
paths = self.create_path_names(layout)
247
cmp_func(path1, path2)
249
def test_py_cmp_dirblock_strings(self):
250
"""Benchmark 103041 comparisons."""
251
self.time(self.compareAllPaths, dirstate.py_cmp_by_dirs,
252
[(3, 1), (3, 1), (3, 1), (3, 2)])
254
def test_c_cmp_dirblock_strings(self):
255
self.requireFeature(CompiledDirstateHelpersFeature)
256
from bzrlib.compiled.dirstate_helpers import c_cmp_by_dirs
257
self.time(self.compareAllPaths, c_cmp_by_dirs,
258
[(3, 1), (3, 1), (3, 1), (3, 2)])