??? 08/02/06 14:21 Read: times |
#121570 - what is best? Responding to: ???'s previous message |
I am very interested in seeing how people on this forum go about optimizing their code. I am usual happy that my functions give me the result I want, and take the "If it ain't broke don't fix it" approach.
That approach is 'the best' when no timing or size issues exsist. When timing and/or size becomes an issue a few 'explorations in the emulator' will gradually get you the knowledge. For instance try coding 3 instances with a switch stement, run it through the cycle counter in the simulator and check the size. The try "if - else if - else if - else" and do the same. Now note, that if you are to replace a switch statement with else you may need more code space, which you may not have, so there will be a trade-off. so what is best? that depends. Then try a few examples of parameter passing replaced with globally stored values. Now note, that if you are to replace passed parameters with global values you will need more data space, which you may or may not have, so there will be a trade-off. so what is best? that depends. Then try the difference between x.y and x->y also x.y.z and x->y->z Now note, that if you are to replace x->y with x.y you may need to copy a structure and copy it back, so there will be a trade-off. so what is best? that depends there is no 'pantyhose solution' sometimes 'a' is the best sometines 'b' or 'c' Experience is a very difficult thing to share. I can comment on specific cases, but cover in general terms my experience to the full extent - I do not see how. Erik |