forked from datalad/datalad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
123 lines (91 loc) · 3.37 KB
/
api.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# ex: set sts=4 ts=4 sw=4 noet:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the datalad package for the
# copyright and license terms.
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Benchmarks of the datalad.api functionality"""
from os.path import join as opj
from datalad.api import create
from datalad.api import create_test_dataset
from datalad.api import install
from datalad.api import ls
from datalad.api import drop
#
# Following ones could be absent in older versions
#
try:
from datalad.api import diff
except ImportError:
diff = None
try:
from datalad.api import status
except ImportError:
status = None
# Some tracking example -- may be we should track # of datasets.datalad.org
#import gc
#def track_num_objects():
# return len(gc.get_objects())
#track_num_objects.unit = "objects"
from .common import (
SampleSuperDatasetBenchmarks,
SuprocBenchmarks,
)
class testds(SuprocBenchmarks):
"""
Benchmarks to test on create_test_dataset how fast we could generate datasets
"""
def time_create_test_dataset1(self):
self.remove_paths.extend(
create_test_dataset(spec='1', seed=0)
)
def time_create_test_dataset2x2(self):
self.remove_paths.extend(
create_test_dataset(spec='2/2', seed=0)
)
class supers(SampleSuperDatasetBenchmarks):
"""
Benchmarks on common operations on collections of datasets using datalad API
"""
def time_installr(self):
# somewhat duplicating setup but lazy to do different one for now
assert install(self.ds.path + '_', source=self.ds.path, recursive=True)
def time_createadd(self):
assert self.ds.create('newsubds')
def time_createadd_to_dataset(self):
subds = create(opj(self.ds.path, 'newsubds'))
self.ds.save(subds.path)
def time_ls(self):
ls(self.ds.path)
def time_ls_recursive(self):
ls(self.ds.path, recursive=True)
def time_ls_recursive_long_all(self):
ls(self.ds.path, recursive=True, long_=True, all_=True)
def time_subdatasets(self):
self.ds.subdatasets()
def time_subdatasets_with_all_paths_recursive(self):
# to see if we do not get O(N^2) performance
subdatasets = self.ds.subdatasets(recursive=True, result_xfm='relpaths')
subdatasets2 = self.ds.subdatasets(path=subdatasets, recursive=True, result_xfm='relpaths')
assert subdatasets == subdatasets2
def time_subdatasets_recursive(self):
self.ds.subdatasets(recursive=True)
def time_subdatasets_recursive_first(self):
next(self.ds.subdatasets(recursive=True, return_type='generator'))
def time_uninstall(self):
for subm in self.ds.repo.get_submodules_():
self.ds.drop(subm["path"], recursive=True, what='all',
reckless='kill')
def time_remove(self):
self.ds.drop(what='all', reckless='kill', recursive=True)
def time_diff(self):
self.ds.diff(fr="HEAD^")
def time_diff_recursive(self):
self.ds.diff(fr="HEAD^", recursive=True)
# Status must be called with the dataset, unlike diff
def time_status(self):
self.ds.status()
def time_status_recursive(self):
self.ds.status(recursive=True)
supers.time_remove.warmup_time = 0