Skip to content

Commit b8f377d

Browse files
committed
add harness support for the default benchmark suites
1 parent 88ced32 commit b8f377d

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2323
# OF THE POSSIBILITY OF SUCH DAMAGE.
2424
# arithmetic ops (partially extracted from spectralnorm)
25-
import time
2625

2726

2827
def docompute(num):
@@ -37,20 +36,10 @@ def docompute(num):
3736

3837

3938
def measure(num):
40-
print("Start timing...")
41-
start = time.time()
42-
4339
for run in range(num):
4440
sum_ = docompute(10000) # 10000
45-
4641
print("sum", sum_)
4742

48-
duration = "%.3f\n" % (time.time() - start)
49-
print("arith-binop: " + duration)
50-
51-
52-
print('warming up ...')
53-
for run in range(2000):
54-
docompute(10) # 1000
5543

56-
measure(5)
44+
def __benchmark__(num=5):
45+
measure(num)

mx.graalpython/mx_graalpython_bench_param.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import mx
2727

2828
py = ".py"
29+
harnessPath = os.path.join('graalpython', 'benchmarks', 'src', 'harness.py')
30+
2931
pathBench = "graalpython/benchmarks/src/benchmarks/"
3032
pathMicro = "graalpython/benchmarks/src/micro/"
3133
pathInterop = "graalpython/benchmarks/src/interop/"
@@ -103,7 +105,7 @@ def _compile_interop():
103105
#
104106
# ----------------------------------------------------------------------------------------------------------------------
105107
pythonMicroBenchmarks = {
106-
'arith-binop': [],
108+
'arith-binop': ['-i', '10', '5'],
107109
'attribute-access': [],
108110
'attribute-access-polymorphic': [],
109111
'attribute-bool': [],

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import mx
3232
from mx_benchmark import StdOutRule, VmRegistry, java_vm_registry, Vm, GuestVm, VmBenchmarkSuite
33-
from mx_graalpython_bench_param import benchmarks_list
33+
from mx_graalpython_bench_param import benchmarks_list, harnessPath
3434

3535
# ----------------------------------------------------------------------------------------------------------------------
3636
#
@@ -52,7 +52,6 @@
5252
SUBGROUP_GRAAL_PYTHON = "graalpython"
5353
PYTHON_VM_REGISTRY_NAME = "Python"
5454
CONFIGURATION_DEFAULT = "default"
55-
_HRULE = ''.join(['-' for _ in range(120)])
5655

5756

5857
# ----------------------------------------------------------------------------------------------------------------------
@@ -61,12 +60,8 @@
6160
#
6261
# ----------------------------------------------------------------------------------------------------------------------
6362
def _check_vm_args(name, args):
64-
if len(args) != 1:
65-
mx.abort("Expected only a single benchmark path, got {} instead".format(args))
66-
benchmark_name = os.path.basename(os.path.splitext(args[0])[0])
67-
print(_HRULE)
68-
print(name, benchmark_name)
69-
print(_HRULE)
63+
if len(args) < 2:
64+
mx.abort("Expected at least 2 args (a single benchmark path in addition to the harness), got {} instead".format(args))
7065

7166

7267
# ----------------------------------------------------------------------------------------------------------------------
@@ -180,8 +175,13 @@ def config_name(self):
180175
#
181176
# ----------------------------------------------------------------------------------------------------------------------
182177
class PythonBenchmarkSuite(VmBenchmarkSuite):
183-
def __init__(self, name):
178+
def __init__(self, name, harness_path):
184179
self._name = name
180+
self._harness_path = harness_path
181+
self._harness_path = join(_graalpython_suite.dir, self._harness_path)
182+
if not self._harness_path:
183+
mx.abort("python harness path not specified!")
184+
185185
self._bench_path, self._benchmarks = benchmarks_list[self._name]
186186
self._bench_path = join(_graalpython_suite.dir, self._bench_path)
187187

@@ -190,10 +190,11 @@ def rules(self, output, benchmarks, bm_suite_args):
190190
arg = " ".join(self._benchmarks[bench_name])
191191
return [
192192
StdOutRule(
193-
r"^(?P<benchmark>[a-zA-Z0-9\.\-]+): (?P<time>[0-9]+(\.[0-9]+)?$)", # pylint: disable=line-too-long
193+
r"^### iteration=(?P<iteration>[0-9]+), name=(?P<benchmark>[a-zA-Z0-9.\-]+), duration=(?P<time>[0-9]+(\.[0-9]+)?$)", # pylint: disable=line-too-long
194194
{
195195
"benchmark": '{}.{}'.format(self._name, bench_name),
196196
"metric.name": "time",
197+
"metric.iteration": ("<iteration>", int),
197198
"metric.type": "numeric",
198199
"metric.value": ("<time>", float),
199200
"metric.unit": "s",
@@ -211,8 +212,8 @@ def createVmCommandLineArgs(self, benchmarks, run_args):
211212

212213
benchmark = benchmarks[0]
213214

214-
cmd_args = [join(self._bench_path, "{}.py".format(benchmark))]
215-
if len(run_args) != 0:
215+
cmd_args = [self._harness_path, join(self._bench_path, "{}.py".format(benchmark))]
216+
if len(run_args) == 0:
216217
cmd_args.extend(self._benchmarks[benchmark])
217218
else:
218219
cmd_args.extend(run_args)
@@ -228,7 +229,7 @@ def benchmarks(self):
228229

229230
def successPatterns(self):
230231
return [
231-
re.compile(r"^(?P<benchmark>[a-zA-Z0-9.\-]+): (?P<score>[0-9]+(\.[0-9]+)?$)", re.MULTILINE)
232+
re.compile(r"^### iteration=(?P<iteration>[0-9]+), name=(?P<benchmark>[a-zA-Z0-9.\-]+), duration=(?P<time>[0-9]+(\.[0-9]+)?$)", re.MULTILINE) # pylint: disable=line-too-long
232233
]
233234

234235
def failurePatterns(self):
@@ -250,7 +251,7 @@ def get_vm_registry(self):
250251

251252
@classmethod
252253
def get_benchmark_suites(cls):
253-
return [cls(suite_name) for suite_name in benchmarks_list]
254+
return [cls(suite_name, harnessPath) for suite_name in benchmarks_list]
254255

255256

256257
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)