thursday/thursday/go_benchmarks.py

67 lines
1.7 KiB
Python

from .external.go_benchmark_functions import *
from inspect import getmro, isclass
_looky_here = False
problems = []
for k in list(locals().keys()):
smth = locals()[k]
if isclass(smth) and Benchmark in getmro(smth)[1:]:
problems.append(smth)
counts = {}
vcount = 0
problems_by_dimensions = {}
for cls in problems:
name = cls.__name__
obj = cls()
n = obj.N
if _looky_here:
print(n, name, "(variable)" if obj.change_dimensionality else "(fixed)")
counts[n] = counts.get(n, 0) + 1
if obj.change_dimensionality:
vcount += 1
dimkey = f"{n}+"
else:
dimkey = f"{n}"
problems_by_dimensions.setdefault(dimkey, []).append(cls)
del obj
counts["variable"] = vcount
if _looky_here:
print(
sorted(
counts.items(),
key=lambda x: f"{x[0]:09}" if isinstance(x[0], int) else str(x[0]),
)
)
p_by_d = problems_by_dimensions
if _looky_here:
for dims in range(2, 6 + 1):
dimp = f"{dims}+"
print(dims, len(p_by_d.get(str(dims), [])), sep="\t")
print(dimp, len(p_by_d.get(dimp, [])), sep="\t")
at_least_2d = p_by_d.get("2+", [])
at_least_3d = p_by_d.get("3+", []) + at_least_2d
at_least_4d = p_by_d.get("4+", []) + at_least_3d
at_least_5d = p_by_d.get("5+", []) + at_least_4d
at_least_6d = p_by_d.get("6+", []) + at_least_5d
problems_2d = p_by_d.get("2", []) + at_least_2d
problems_3d = p_by_d.get("3", []) + at_least_3d
problems_4d = p_by_d.get("4", []) + at_least_4d
problems_5d = p_by_d.get("5", []) + at_least_5d
problems_6d = p_by_d.get("6", []) + at_least_6d
all_problems = {
2: problems_2d,
3: problems_3d,
4: problems_4d,
5: problems_5d,
6: problems_6d,
}