Skip to content

Commit 88ced32

Browse files
committed
harness support for args processor, default processor will convert all args to ints
1 parent 7326e72 commit 88ced32

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

graalpython/benchmarks/src/harness.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
_HRULE = '-'.join(['' for i in range(80)])
4646
ATTR_BENCHMARK = '__benchmark__'
47+
ATTR_PROCESS_ARGS = '__process_args__'
4748

4849

4950
def _as_int(value):
@@ -94,26 +95,34 @@ def _get_attr(self, attr_name):
9495
if hasattr(self.bench_module, attr_name):
9596
return getattr(self.bench_module, attr_name)
9697

97-
def _call_attr(self, attr_name):
98+
def _call_attr(self, attr_name, *args):
9899
attr = self._get_attr(attr_name)
99100
if attr and hasattr(attr, '__call__'):
100-
attr()
101+
return attr(*args)
101102

102103
def run(self):
103104
print(_HRULE)
104105
print("### %s, %s warmup iterations, %s bench iterations " % (self.bench_module.__name__, self.warmup, self.iterations))
106+
107+
# process the args if the processor function is defined
108+
args = self._call_attr(ATTR_PROCESS_ARGS, *self.bench_args)
109+
if args is None:
110+
# default args processor considers all args as ints
111+
args = list(map(int, self.bench_args))
112+
113+
print("### args = %s" % args)
105114
print(_HRULE)
106115

107116
bench_func = self._get_attr(ATTR_BENCHMARK)
108117
if bench_func and hasattr(bench_func, '__call__'):
109118
if self.warmup:
110119
print("### warming up for %s iterations ... " % self.warmup)
111120
for _ in range(self.warmup):
112-
bench_func(*self.bench_args)
121+
bench_func(*args)
113122

114123
for iteration in range(self.iterations):
115124
start = time()
116-
bench_func(*self.bench_args)
125+
bench_func(*args)
117126
duration = "%.3f" % (time() - start)
118127
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration))
119128

0 commit comments

Comments
 (0)