benchtests: Add new directive for benchmark initialization hook
Commit Message
Add a new 'init' directive that specifies the name of the function to
call to do function-specific initialization. This is useful for
benchmarks that need to do a one-time initialization before the
functions are executed.
Siddhesh
* benchtests/README: Document 'init' directive.
* benchtests/bench-skeleton.c (main) [BENCH_INIT]: Call
BENCH_INIT.
* scripts/bench.py (gen_source): Define BENCH_INIT macro.
(parse_file): Recognize 'init' directive.
---
benchtests/README | 1 +
benchtests/bench-skeleton.c | 3 +++
scripts/bench.py | 7 ++++++-
3 files changed, 10 insertions(+), 1 deletion(-)
@@ -60,6 +60,7 @@ one to add `foo' to the bench tests:
- include-sources: This should be assigned a comma-separated list of source
files that need to be included to provide definitions of global variables
and functions (specifically, this includes using "#include "source").
+ - init: Name of an initializer function to call to initialize the benchtest.
- name: See following section for instructions on how to use this directive.
Lines beginning with a single hash '#' are treated as comments. See
@@ -55,6 +55,9 @@ main (int argc, char **argv)
unsigned long iters, res;
+#ifdef BENCH_INIT
+ BENCH_INIT ();
+#endif
TIMING_INIT (res);
iters = 1000 * res;
@@ -124,6 +124,10 @@ def gen_source(func, directives, all_vals):
else:
getret = ''
+ # Test initialization.
+ if directives['init']:
+ print('#define BENCH_INIT %s' % directives['init'])
+
print(EPILOGUE % {'getret': getret, 'func': func})
@@ -228,7 +232,8 @@ def parse_file(func):
'args': [],
'includes': [],
'include-sources': [],
- 'ret': ''
+ 'ret': '',
+ 'init': ''
}
try: