Altera_Forum
Honored Contributor
11 years agoNIOS-II C Code optimization
I have defined a code looks like below:
Style 1: function() { variable declaration and initialization int N; N= read_iteration(); for (n=0; n< N; n++) { if (some expression) { do some assignments and expression computation } } Style 2: function() { variable declaration and initialization int N; N= read_iteration(); for (n=0; n< N ; n++) { if (some expression) { do some assignments and expression computation } else { do some other assignment and expression computation } } The 'some expression' in the 'If' clause always evaluates to TRUE in the above two Styles. However, for Style 2 the function takes about 12% extra time compared to style 1. Any suggestion why is this happening and how to optimize it so that the two takes approximately the same time.