Skip to content

Commit

Permalink
test complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jagerber48 committed Dec 17, 2024
1 parent d532874 commit c6c6128
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from math import log10
import time
import timeit

Expand All @@ -20,16 +21,18 @@ def time_ufloat_sum_benchmark(num):
return t / reps


def test_algorithm_complexity():
def test_complexity():
result_dict = {}
n_list = (10, 100, 1000, 10000, 100000)
for n in n_list:
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
if n == n0:
continue
# Check that the plot of t vs n is linear on a log scale to within 10%
assert 0.9 * log10(n / n0) < log10(t / t0) < 1.1 * log10(n / n0)


@pytest.mark.benchmark
Expand Down

0 comments on commit c6c6128

Please sign in to comment.