| 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 for DataLad""" |
| 9 |
|
| 10 |
import os |
| 11 |
import os.path as osp |
| 12 |
import sys |
| 13 |
from subprocess import call |
| 14 |
|
| 15 |
from datalad.runner import ( |
| 16 |
GitRunner, |
| 17 |
Runner, |
| 18 |
StdOutErrCapture, |
| 19 |
) |
| 20 |
|
| 21 |
from .common import SuprocBenchmarks |
| 22 |
|
| 23 |
# Some tracking example -- may be we should track # of datasets.datalad.org |
| 24 |
#import gc |
| 25 |
#def track_num_objects(): |
| 26 |
# return len(gc.get_objects()) |
| 27 |
#track_num_objects.unit = "objects" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
scripts_dir = osp.join(osp.dirname(__file__), 'scripts') |
| 32 |
heavyout_cmd = "{} 1000".format(osp.join(scripts_dir, 'heavyout')) |
| 33 |
|
| 34 |
|
| 35 |
class startup(SuprocBenchmarks): |
| 36 |
""" |
| 37 |
Benchmarks for datalad commands startup |
| 38 |
""" |
| 39 |
|
| 40 |
def setup(self): |
| 41 |
# we need to prepare/adjust PATH to point to installed datalad |
| 42 |
# We will base it on taking sys.executable |
| 43 |
python_path = osp.dirname(sys.executable) |
| 44 |
self.env = os.environ.copy() |
| 45 |
self.env['PATH'] = '%s:%s' % (python_path, self.env.get('PATH', '')) |
| 46 |
|
| 47 |
def time_import(self): |
| 48 |
call([sys.executable, "-c", "import datalad"]) |
| 49 |
|
| 50 |
def time_import_api(self): |
| 51 |
call([sys.executable, "-c", "import datalad.api"]) |
| 52 |
|
| 53 |
|
| 54 |
class witlessrunner(SuprocBenchmarks): |
| 55 |
"""Some rudimentary tests to see if there is no major slowdowns of Runner |
| 56 |
""" |
| 57 |
|
| 58 |
def setup(self): |
| 59 |
self.runner = Runner() |
| 60 |
self.git_runner = GitRunner() |
| 61 |
|
| 62 |
def time_echo(self): |
| 63 |
self.runner.run(["echo"]) |
| 64 |
|
| 65 |
def time_echo_gitrunner(self): |
| 66 |
self.git_runner.run(["echo"]) |
| 67 |
|
| 68 |
def time_echo_gitrunner_fullcapture(self): |
| 69 |
self.git_runner.run(["echo"], protocol=StdOutErrCapture) |