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