forked from SpikeInterface/spikeinterface
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport_test.py
More file actions
72 lines (59 loc) · 2.65 KB
/
import_test.py
File metadata and controls
72 lines (59 loc) · 2.65 KB
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
import subprocess
import math
import_statement_list = [
"import spikeinterface",
"import spikeinterface.core",
"import spikeinterface.extractors",
"import spikeinterface.metrics",
"import spikeinterface.preprocessing",
"import spikeinterface.comparison",
"import spikeinterface.postprocessing",
"import spikeinterface.sortingcomponents",
"import spikeinterface.curation",
"import spikeinterface.exporters",
"import spikeinterface.widgets",
"import spikeinterface.full",
]
n_samples = 10
# Note that the symbols at the end are for centering the table
markdown_output = f"## \n\n| Imported Module ({n_samples=}) | Importing Time (seconds) | Standard Deviation (seconds) | Times List (seconds) |\n| :--: | :--------------: | :------------------: | :-------------: |\n"
exceptions = []
for import_statement in import_statement_list:
time_taken_list = []
for _ in range(n_samples):
script_to_execute = (
f"import timeit \n"
f"import_statement = '{import_statement}' \n"
f"time_taken = timeit.timeit(import_statement, number=1) \n"
f"print(time_taken) \n"
)
result = subprocess.run(["python", "-c", script_to_execute], capture_output=True, text=True)
if result.returncode != 0:
error_message = (
f"Error when running {import_statement} \n" f"Error in subprocess: {result.stderr.strip()}\n"
)
exceptions.append(error_message)
break
time_taken = float(result.stdout.strip())
time_taken_list.append(time_taken)
for time in time_taken_list:
import_time_threshold = 3.0 # Most of the times is sub-second but there outliers
if time >= import_time_threshold:
exceptions.append(
f"Importing {import_statement} took: {time:.2f} s. Should be <: {import_time_threshold} s."
)
break
if time_taken_list:
avg_time = sum(time_taken_list) / len(time_taken_list)
std_time = math.sqrt(sum((x - avg_time) ** 2 for x in time_taken_list) / len(time_taken_list))
times_list_str = ", ".join(f"{time:.2f}" for time in time_taken_list)
markdown_output += f"| `{import_statement}` | {avg_time:.2f} | {std_time:.2f} | {times_list_str} |\n"
import_time_threshold = 2.0
if avg_time > import_time_threshold:
exceptions.append(
f"Importing {import_statement} took: {avg_time:.2f} s in average. Should be <: {import_time_threshold} s."
)
if exceptions:
raise Exception("\n".join(exceptions))
# This is displayed to GITHUB_STEP_SUMMARY
print(markdown_output)