It seems that you are comparing the sizes of the .S
files generated by GCC, since that obviously make no sense, I'm just pretending you were confronting the binary size of two, GCC generated, code snippets.
While, having all other conditions the same, a shorter code size may gives an increase in speed (due to an higher code density), in general x86 CPUs are complex enough to require a decoupling between optimizations for code size and optimizations for code speed.
Specifically if you aim at code speed you should optimize for... code speed. Sometime this require choosing the shortest snippet, sometime it doesn't.
Consider the classic example of compiler optimization, multiplication by powers of two:
int i = 4;
i = i * 8;
This may be badly translated as:
;NO optimizations at all
mov eax, 4 ;i = 4 B804000000 0-1 clocks
imul eax, 8 ;i = i * 8 6BC009 3 clocks
;eax = i 8 bytes total 3-4 clocks total
;Slightly optimized
;4*8 gives no sign issue, we can use shl
mov eax, 4 ;i = 4 B804000000 0-1 clocks
shl eax, 3 ;i = i * 8 C1E003 1 clock
;eax = i 8 bytes total 1-2 clocks total
Both snippets have the same code length but the second performs nearly as twice as faster.
This is a very basic example1, where there is not even much need to take the micro-architecture into account.
Another more subtle example is the following, taken from Agner Fog discussion of Partial register stalls2:
;Version A Version B
mov al, byte ptr [mem8] movzx ebx, byte ptr [mem8]
mov ebx, eax and eax, 0ffffff00h
or ebx, eax
;7 bytes 14 bytes
Both versions give the same result but Version B is 5-6 clocks faster than Version A despite the former being twice the size of the latter.
The answer is then no, code size is not enough; it may be a tie-breaker though.
If you really are interested into optimizing assembly you will enjoy these two readings:
The first link also have a manual to optimize C and C++ code.
If you write in C remember that the most impacting optimizations are 1) How data is represented/stored, i.e. Data structures 2) How data is processed, i.e. Algorithms.
There are the macro optimizations.
Taking into account the generated assembly is shifting into micro optimization and there the most useful tools are 1) A smart compiler 2) A good set of intrinsics3.
1 So simple to be optimized out in practice.
2 Maybe a little obsolete now but it serves the purpose.
3 Built-in, non standard, functions that translate into specific assembly instructions.