From 184753a6cf10bf24b50b06c66ea2a2ba8bedc6b3 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 10 May 2020 09:45:24 +0200 Subject: make benchmark definitions more pythonic Don't export a singleton object in the definiton. An object is now created when the Benchmark should be executed, thus we don't need a prepare method this can be done in __init__ --- bench.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'bench.py') diff --git a/bench.py b/bench.py index 95f114b..b440011 100755 --- a/bench.py +++ b/bench.py @@ -30,7 +30,7 @@ from allocbench.allocator import collect_allocators from allocbench.analyse import analyze_bench, analyze_allocators import allocbench.facter as facter import allocbench.globalvars -from allocbench.util import find_cmd, run_cmd +from allocbench.util import run_cmd from allocbench.util import print_status, print_warn, print_error from allocbench.util import print_info, print_info2, print_debug from allocbench.util import print_license_and_exit @@ -176,20 +176,21 @@ def main(): bench_module = importlib.import_module( f"allocbench.benchmarks.{bench}") - if not hasattr(bench_module, bench): - print_error(f"{bench_module} has no member {bench}.") - print_error(f"Skipping {bench_module}") - continue - - bench = getattr(bench_module, bench) + # find Benchmark class + for member in bench_module.__dict__.values(): + if (isinstance(member, type) + or member is allocbench.benchmark.Benchmark + or not issubclass(member, allocbench.benchmark.Benchmark)): + continue - print_status("Preparing", bench.name, "...") - try: - bench.prepare() - except Exception: - print_error(traceback.format_exc()) - print_error(f"Skipping {bench}! Preparing failed.") - continue + try: + print_status("Preparing", bench, "...") + bench = member() + break + except Exception: + print_error(traceback.format_exc()) + print_error(f"Skipping {bench}! Preparing failed.") + continue if args.analyze: analyze_bench(bench) -- cgit v1.2.3