aboutsummaryrefslogtreecommitdiff
path: root/bench.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-05-10 09:45:24 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-06-02 11:18:47 +0200
commit184753a6cf10bf24b50b06c66ea2a2ba8bedc6b3 (patch)
treea6b1b62b944af32eeff134cd038734d139e389d7 /bench.py
parentd5eed692fcd281d942853fbcb5a5685476d326d9 (diff)
downloadallocbench-184753a6cf10bf24b50b06c66ea2a2ba8bedc6b3.tar.gz
allocbench-184753a6cf10bf24b50b06c66ea2a2ba8bedc6b3.zip
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__
Diffstat (limited to 'bench.py')
-rwxr-xr-xbench.py29
1 files changed, 15 insertions, 14 deletions
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)