-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8425756
commit b3e66a1
Showing
2 changed files
with
15 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,32 @@ | ||
import platform | ||
import timeit | ||
|
||
import psutil | ||
import pytest | ||
|
||
from uncertainties import ufloat | ||
|
||
|
||
def print_system_info(): | ||
sys_info = { | ||
"platform": platform.system(), | ||
"platform-release": platform.release(), | ||
"platform-version": platform.version(), | ||
"architecture": platform.machine(), | ||
"processor": platform.processor(), | ||
"ram": str(round(psutil.virtual_memory().total / (1024.0**3))) + " GB", | ||
} | ||
|
||
for key, value in sys_info.items(): | ||
print(f"{key:17}: {value}") | ||
def ufloat_sum_benchmark(num): | ||
sum(ufloat(1, 1) for _ in range(num)).std_dev | ||
|
||
|
||
def ufloat_sum_benchmark(num): | ||
str(sum(ufloat(1, 1) for _ in range(num))) | ||
def time_ufloat_sum_benchmark(num): | ||
reps = int(100000 / num) | ||
t = timeit.timeit(lambda: ufloat_sum_benchmark(num), number=reps) | ||
return t / reps | ||
|
||
|
||
def test_algorithm_performance(): | ||
print_system_info() | ||
def test_algorithm_complexity(): | ||
result_dict = {} | ||
n_list = (10, 100, 1000, 10000, 100000) | ||
for n in n_list: | ||
print(f"### {n=} ###") | ||
reps = int(100000 / n) | ||
t = timeit.timeit(lambda: ufloat_sum_benchmark(n), number=reps) | ||
t_avg = t / reps | ||
print(f" Test duration: {t:.2f} s, Repetitions: {reps}") | ||
print(f" Average execution time: {t_avg:.4f} s") | ||
result_dict[n] = t_avg | ||
result_dict[n] = time_ufloat_sum_benchmark(n) | ||
n0 = n_list[0] | ||
t0 = result_dict[n0] | ||
for n, t in result_dict.items(): | ||
assert 1 / 4 < (t / n) / (t0 / n0) < 4 | ||
assert result_dict[100000] < 0.75 * 4 | ||
|
||
|
||
@pytest.mark.benchmark | ||
def test_speed(): | ||
time_ufloat_sum_benchmark(100000) |