|
44 | 44 |
|
45 | 45 | _HRULE = '-'.join(['' for i in range(80)]) |
46 | 46 | ATTR_BENCHMARK = '__benchmark__' |
| 47 | +ATTR_PROCESS_ARGS = '__process_args__' |
47 | 48 |
|
48 | 49 |
|
49 | 50 | def _as_int(value): |
@@ -94,26 +95,34 @@ def _get_attr(self, attr_name): |
94 | 95 | if hasattr(self.bench_module, attr_name): |
95 | 96 | return getattr(self.bench_module, attr_name) |
96 | 97 |
|
97 | | - def _call_attr(self, attr_name): |
| 98 | + def _call_attr(self, attr_name, *args): |
98 | 99 | attr = self._get_attr(attr_name) |
99 | 100 | if attr and hasattr(attr, '__call__'): |
100 | | - attr() |
| 101 | + return attr(*args) |
101 | 102 |
|
102 | 103 | def run(self): |
103 | 104 | print(_HRULE) |
104 | 105 | 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) |
105 | 114 | print(_HRULE) |
106 | 115 |
|
107 | 116 | bench_func = self._get_attr(ATTR_BENCHMARK) |
108 | 117 | if bench_func and hasattr(bench_func, '__call__'): |
109 | 118 | if self.warmup: |
110 | 119 | print("### warming up for %s iterations ... " % self.warmup) |
111 | 120 | for _ in range(self.warmup): |
112 | | - bench_func(*self.bench_args) |
| 121 | + bench_func(*args) |
113 | 122 |
|
114 | 123 | for iteration in range(self.iterations): |
115 | 124 | start = time() |
116 | | - bench_func(*self.bench_args) |
| 125 | + bench_func(*args) |
117 | 126 | duration = "%.3f" % (time() - start) |
118 | 127 | print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration)) |
119 | 128 |
|
|
0 commit comments