Speed of the CODE

I am in the process of doing some number crunching which involves multiplying several matrices (usually 12x12) frequently. However lot of the entries in these matrices are 0 or 1. I have written a code in Matlab which symbolically computes the output and then converts it directly to c++ code.

Say if i am multiplying matrices M1 and M2 and M3 = M1*M2. Internally storage is a as a double array in contiguous blocks of memory. The c++ code i get from my Matlab script has expressions of the form

M3[0] = VERY_LONG_EXPRESSION;
M3[1] = VERY_LONG_EXPRESSION, etc...

Does this long expression slow the c++ code down ? Is it advisable to have some smaller intermediate double variables ? For example, suppose
VERY_LONG_EXPRESSION = EXPRESSION1 + EXPRESSION2.
Then i could have the following code
1
2
3
4
double E1,E2;
E1 = EXPRESSION1;
E2 = EXPRESSION2;
M3[0] = E1+E2


Alternatively, I could use several intermediate double variables to cut down the size of the VERY_LONG_EXPRESSION. Which approach would result in the fastest code ? Readability of the code is not an issue here. I am only interested in number crunching and speed of the code.

Any suggestions ?
Thanks.
Let others do the debugging and optimization for you.

For example, use LAPACK (http://en.wikipedia.org/wiki/LAPACK) or some other numerical library.
Problem solved. I just found ccode in Matlab. Its awesome !
Topic archived. No new replies allowed.