Skip to content

Commit 339300f

Browse files
committed
[GR-12096] reusable graalpython benchmarking constructs
PullRequest: graalpython/233
2 parents 54fbc31 + 8966788 commit 339300f

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

graalpython/benchmarks/src/harness.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
_HRULE = '-'.join(['' for i in range(80)])
4747
ATTR_BENCHMARK = '__benchmark__'
4848
ATTR_PROCESS_ARGS = '__process_args__'
49+
ATTR_TEARDOWN = '__teardown__'
4950

5051

5152
def ccompile(name, code):
@@ -162,6 +163,10 @@ def run(self):
162163
else:
163164
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration))
164165

166+
print("teardown ... ")
167+
self._call_attr(ATTR_TEARDOWN)
168+
print("benchmark complete")
169+
165170

166171
def run_benchmark(prog, args):
167172
warmup = 0

graalpython/benchmarks/src/micro/arith-binop.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ def measure(num):
4343

4444
def __benchmark__(num=5):
4545
measure(num)
46+
47+
48+
def __teardown__():
49+
# teardown example
50+
print("arith-binop teardown")

mx.graalpython/mx_graalpython.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import mx_subst
3737
import mx_urlrewrites
3838
from mx_gate import Task
39-
from mx_graalpython_bench_param import PATH_MESO
39+
from mx_graalpython_bench_param import PATH_MESO, BENCHMARKS
4040
from mx_graalpython_benchmark import PythonBenchmarkSuite
4141
from mx_unittest import unittest
4242

@@ -424,7 +424,7 @@ def graalpython_gate_runner(args, tasks):
424424
apprepo = os.environ["GRAALPYTHON_APPTESTS_REPO_URL"]
425425
_apptest_suite = _suite.import_suite(
426426
"graalpython-apptests",
427-
version="006db2cfd79a51ba49e23a42629da13a54b87451",
427+
version="fe1458e3af707f5996f192aedc7b76585501e8ba",
428428
urlinfos=[mx.SuiteImportURLInfo(mx_urlrewrites.rewriteurl(apprepo), "git", mx.vc_system("git"))]
429429
)
430430
mx.run_mx(["-p", _apptest_suite.dir, "graalpython-apptests"])
@@ -868,7 +868,7 @@ def import_python_sources(args):
868868
# add the defined python benchmark suites
869869
#
870870
# ----------------------------------------------------------------------------------------------------------------------
871-
for py_bench_suite in PythonBenchmarkSuite.get_benchmark_suites():
871+
for py_bench_suite in PythonBenchmarkSuite.get_benchmark_suites(BENCHMARKS):
872872
mx_benchmark.add_bm_suite(py_bench_suite)
873873

874874

mx.graalpython/mx_graalpython_bench_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_graalpython_suite = mx.suite('graalpython')
2929

3030
py = ".py"
31-
_BASE_PATH = os.path.join('graalpython', 'benchmarks', 'src')
31+
_BASE_PATH = os.path.join(_graalpython_suite.dir, 'graalpython', 'benchmarks', 'src')
3232
HARNESS_PATH = os.path.join(_BASE_PATH, 'harness.py')
3333

3434
PATH_BENCH = os.path.join(_BASE_PATH, 'benchmarks')

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ def config_name(self):
183183
#
184184
# ----------------------------------------------------------------------------------------------------------------------
185185
class PythonBenchmarkSuite(VmBenchmarkSuite, AveragingBenchmarkMixin):
186-
def __init__(self, name, harness_path):
186+
def __init__(self, name, bench_path, benchmarks):
187187
self._name = name
188-
self._harness_path = harness_path
188+
self._harness_path = HARNESS_PATH
189189
self._harness_path = join(_graalpython_suite.dir, self._harness_path)
190190
if not self._harness_path:
191191
mx.abort("python harness path not specified!")
192192

193-
self._bench_path, self._benchmarks = BENCHMARKS[self._name]
193+
self._bench_path, self._benchmarks = bench_path, benchmarks
194194
self._bench_path = join(_graalpython_suite.dir, self._bench_path)
195195

196196
def rules(self, output, benchmarks, bm_suite_args):
@@ -292,8 +292,10 @@ def get_vm_registry(self):
292292
return python_vm_registry
293293

294294
@classmethod
295-
def get_benchmark_suites(cls):
296-
return [cls(suite_name, HARNESS_PATH) for suite_name in BENCHMARKS]
295+
def get_benchmark_suites(cls, benchmarks):
296+
assert isinstance(benchmarks, dict), "benchmarks must be a dict: {suite: [path, benchmarks], ...}"
297+
return [cls(suite_name, suite_info[0], suite_info[1])
298+
for suite_name, suite_info in benchmarks.items()]
297299

298300

299301
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)