diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-13 16:26:06 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-13 16:26:06 +0100 |
commit | e8428262c13c6b3727d9cebeb9a51a0dd83a10ca (patch) | |
tree | 672c12892c1e6b5edc373f82fdc791147176e2dd | |
parent | 0c132a304eb001dcd7ff9ee578854c92686fe15b (diff) |
Add simple per-statement C(++) timing analysis wrapper
-rw-r--r-- | lib/utils.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py index e86b85d..c53d531 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,4 +1,5 @@ import numpy as np +import re arg_support_enabled = True @@ -168,3 +169,31 @@ def _all_params_are_numeric(data, param_idx): if len(list(filter(is_numeric, param_values))) == len(param_values): return True return False + +class TimingAnalysis: + def __init__(self, enabled = True): + self.enabled = enabled + self.index = 1 + + def get_header(self): + ret = '' + if self.enabled: + ret += '#define TIMEIT(index, functioncall) ' + ret += 'counter.start(); ' + ret += 'functioncall; ' + ret += 'counter.stop();' + ret += 'kout << endl << index << " :: " << counter.value << "/" << counter.overflow << endl;' + return ret + + def wrap_codeblock(self, codeblock): + if not self.enabled: + return codeblock + lines = codeblock.split('\n') + ret = list() + for line in lines: + if re.fullmatch('.+;', line): + ret.append('TIMEIT( {:d}, {} )'.format(self.index, line)) + self.index += 1 + else: + ret.append(line) + return '\n'.join(ret) |