File: path.py

package info (click to toggle)
datalad 1.1.5-2.1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,140 kB
  • sloc: python: 69,392; sh: 1,521; makefile: 220
file content (41 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Import functions to be tested with _ suffix and name the suite after the
# original function so we could easily benchmark it e.g. by
#    asv run --python=same -b get_parent_paths
# without need to discover what benchmark to use etc

from datalad.support.path import get_parent_paths as get_parent_paths_

from ..common import SuprocBenchmarks


class get_parent_paths(SuprocBenchmarks):

    def setup(self):
        # prepare some more or less realistic with a good number of paths
        # and some hierarchy of submodules
        self.nfiles = 40  # per each construct
        self.nsubmod = 30  # at two levels
        self.toplevel_submods = ['submod%d' % i for i in range(self.nsubmod)]
        self.posixpaths = \
            ['file%d' % i for i in range(self.nfiles)] + \
            ['subdir/anotherfile%d' % i for i in range(self.nfiles)]
        for submod in range(self.nsubmod):
            self.posixpaths += \
                ['submod%d/file%d' % (submod, i) for i in range(self.nfiles)] + \
                ['subdir/submod%d/file%d' % (submod, i) for i in range(self.nfiles)] + \
                ['submod/sub%d/file%d' % (submod, i) for i in range(self.nfiles)]

    def time_no_submods(self):
        assert get_parent_paths_(self.posixpaths, [], True) == []

    def time_one_submod_toplevel(self):
        get_parent_paths_(self.posixpaths, ['submod9'], True)

    def time_one_submod_subdir(self):
        get_parent_paths_(self.posixpaths, ['subdir/submod9'], True)

    def time_allsubmods_toplevel_only(self):
        get_parent_paths_(self.posixpaths, self.toplevel_submods, True)

    def time_allsubmods_toplevel(self):
        get_parent_paths_(self.posixpaths, self.toplevel_submods)