diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-13 15:00:34 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-13 15:00:34 -0700 |
commit | 17ba5c2b0712b8c871a260f3e1ce00527c5a4d1d (patch) | |
tree | ecfd30f856214dc6fb74c31c6635439f7b6bad56 /tests/test_benchmark.py | |
parent | eef1e214a698ae6e4f8b2c375536b268f0a95dd2 (diff) |
conditionalize in all boolean-emitting expressions
Diffstat (limited to 'tests/test_benchmark.py')
-rw-r--r-- | tests/test_benchmark.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 821caa6b..16abbfdd 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -408,6 +408,42 @@ class benchmark(RunnerCore): ''' self.do_benchmark('ifs', src, 'ok', reps=TEST_REPS*5) + def test_conditionals(self): + src = r''' + #include <stdio.h> + #include <stdlib.h> + + int main(int argc, char *argv[]) { + int arg = argc > 1 ? argv[1][0] - '0' : 3; + switch(arg) { + case 0: return 0; break; + case 1: arg = 3*75; break; + case 2: arg = 3*625; break; + case 3: arg = 3*1250; break; + case 4: arg = 3*5*1250; break; + case 5: arg = 3*10*1250; break; + default: printf("error: %d\\n", arg); return -1; + } + + int x = 0; + + for (int j = 0; j < 27000; j++) { + for (int i = 0; i < arg; i++) { + if (((x*x+11) % 3 == 0) | ((x*(x+2)+17) % 5 == 0)) { + x += 2; + } else { + x++; + } + } + } + + printf("ok %d\n", x); + + return x; + } + ''' + self.do_benchmark('conditionals', src, 'ok', reps=TEST_REPS*5) + def test_fannkuch(self): src = open(path_from_root('tests', 'fannkuch.cpp'), 'r').read().replace( 'int n = argc > 1 ? atoi(argv[1]) : 0;', |