Skip to content

Commit a2604d4

Browse files
Merge pull request #63 from dvklopfenstein/dev
Improved timing test
2 parents c77cb0a + 74a45d5 commit a2604d4

File tree

1 file changed

+64
-25
lines changed

1 file changed

+64
-25
lines changed

tests/test_tt_fncs.py

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,73 @@ def test_tt_fncs(num_p_batch=1):
2424
mintime_fast = min(mintime_fast, timedelta(seconds=default_timer()-tic))
2525
print(mintime_fast)
2626

27-
assert mintime_fast < mintime_slow
27+
_chk(mintime_slow, mintime_fast, 'import-all-fncs', 'import-one-fnc')
2828

29-
faster = mintime_slow.total_seconds()/mintime_fast.total_seconds()
30-
print(f'{faster:10.1f} times faster is import fncs compared to regular import')
3129

30+
def test_tt_ospath_a(num_p_batch=1000):
31+
"""Test speed savings from lazy import"""
32+
# pylint: disable=import-outside-toplevel
33+
mintime_slow = _mintime_os_pathn(num_p_batch)
34+
mintime_fast = _mintime_os_path1(num_p_batch)
35+
_chk(mintime_slow, mintime_fast, 'os.path', 'os_path')
3236

33-
def test_tt_ospath(num_p_batch=1):
37+
def test_tt_ospath_b(num_p_batch=1000):
3438
"""Test speed savings from lazy import"""
35-
# pylint: disable=import-outside-toplevel,too-many-locals
39+
# pylint: disable=import-outside-toplevel
40+
mintime_slow = _mintime_os_pathn(num_p_batch)
41+
mintime_fastb = _mintime_os_path1b(num_p_batch)
42+
_chk(mintime_slow, mintime_fastb, 'os.path', 'os_path + fncs')
43+
44+
45+
46+
def _chk(mintime_slow, mintime_fast, slow_desc, fast_desc):
47+
if mintime_fast > mintime_slow:
48+
print(f'FAST[{fast_desc}]({mintime_fast}) NOT < '
49+
f'SLOW[{slow_desc}]({mintime_slow})')
50+
51+
if (min_secs := mintime_fast.total_seconds()) != 0:
52+
faster = mintime_slow.total_seconds()/min_secs
53+
print(f'{faster:10.1f} times faster is import {fast_desc} '
54+
f'compared to import {slow_desc}')
55+
56+
57+
def _mintime_os_path1(num_p_batch):
58+
mintime_fast = timedelta(seconds=1000)
59+
for _ in range(num_p_batch):
60+
tic = default_timer()
61+
# pylint: disable=import-outside-toplevel
62+
import os.path as os_path
63+
mintime_fast = min(mintime_fast, timedelta(seconds=default_timer()-tic))
64+
del os_path
65+
print(mintime_fast)
66+
return mintime_fast
67+
68+
def _mintime_os_path1b(num_p_batch):
69+
mintime_fast = timedelta(seconds=1000)
70+
for _ in range(num_p_batch):
71+
tic = default_timer()
72+
# pylint: disable=import-outside-toplevel
73+
import os.path as os_path
74+
# pylint: disable=pointless-statement
75+
os_path.exists
76+
os_path.relpath
77+
os_path.abspath
78+
os_path.dirname
79+
os_path.join
80+
os_path.ismount
81+
os_path.basename
82+
os_path.normpath
83+
os_path.realpath
84+
mintime_fast = min(mintime_fast, timedelta(seconds=default_timer()-tic))
85+
del os_path
86+
print(mintime_fast)
87+
return mintime_fast
88+
89+
def _mintime_os_pathn(num_p_batch):
3690
mintime_slow = timedelta(seconds=1000)
3791
for _ in range(num_p_batch):
3892
tic = default_timer()
93+
# pylint: disable=import-outside-toplevel
3994
from os.path import exists
4095
from os.path import relpath
4196
from os.path import abspath
@@ -45,8 +100,7 @@ def test_tt_ospath(num_p_batch=1):
45100
from os.path import basename
46101
from os.path import normpath
47102
from os.path import realpath
48-
from logging import debug
49-
from timetracker.consts import DIRTRK
103+
mintime_slow = min(mintime_slow, timedelta(seconds=default_timer()-tic))
50104
del exists
51105
del relpath
52106
del abspath
@@ -56,25 +110,10 @@ def test_tt_ospath(num_p_batch=1):
56110
del basename
57111
del normpath
58112
del realpath
59-
del debug
60-
del DIRTRK
61-
mintime_slow = min(mintime_slow, timedelta(seconds=default_timer()-tic))
62113
print(mintime_slow)
63-
64-
mintime_fast = timedelta(seconds=1000)
65-
for _ in range(num_p_batch):
66-
tic = default_timer()
67-
import os.path as os_path
68-
del os_path
69-
mintime_fast = min(mintime_fast, timedelta(seconds=default_timer()-tic))
70-
print(mintime_fast)
71-
72-
assert mintime_fast < mintime_slow
73-
74-
faster = mintime_slow.total_seconds()/mintime_fast.total_seconds()
75-
print(f'{faster:10.1f} times faster is import fncs compared to regular import')
76-
114+
return mintime_slow
77115

78116
if __name__ == '__main__':
79117
test_tt_fncs()
80-
test_tt_ospath()
118+
test_tt_ospath_a()
119+
test_tt_ospath_b()

0 commit comments

Comments
 (0)