|If i understand you correctly you are wondered why a program optimized for speed uses more memory and a program optimized for size is mostly slower.
I think there are 3 ways to optimize a program:
1. Get rid of all unneeded code. Classic examples are:
- the programmer lost oversight of variables resulting in several variables holding the same value
- He's insecure what value is in a variable resulting in too many conditions asking the same question
- Using the wrong algorithm to solve a problem
This kind of optimizing is for free: you will end with a program that uses less memory and less CPU
2. If your program does not contain any unneeded code, the only thing left is trade between memory, CPU and time. Your program says: i need this number of sourcode lines to solve the problem. Thus you only can restate lines, change computation into memory usage. This kind of optimizing has its costs: less CPU is more memory and v.v.
3. Sometimes you can divide a CPU-consuming piece in several parts that can be done when the program waits for the user. This kind of optimizing essentially does nothing (it still consumes the same time) but changes the feeling of the user. (actually you are not manipulating the program but the user).
I think a more interresting question would be: how can you garantuee that your program does not contain any needless code....