3 ms·
Another reason to pay attention to #2: Most CPUs perform simple arithmetic operations fastest on their native word size. On a 32-bit machine, addition and subtr
by wtracy 13y ago
Another reason to pay attention to #2: Most CPUs perform simple arithmetic operations fastest on their native word size. On a 32-bit machine, addition and subtraction on 8-bit variables is probably slower than on 32-bit variables. (Often the hardware will transparently cast to 32 bits, perform the operation, then cast back to 8 bits.)
I'm not an authority on this topic, so I don't want you to take away the message "always use the machine word size". What I do want you to take away is that there are many cases where an "obvious" optimization is counterproductive in practice. Always start with simple, working code, and never optimize without benchmarking.
- alecrn 13y agoFor this case, the "fast" int types are provided, eg. uint_fast8_t is the fastest unsigned integer which can hold at least 8 bits; uint8_t is required to have exactly 8 bits. http://pubs.opengroup.org/onlinepubs/7999959899/basedefs/stdint.h.html http://pubs.opengroup.org/onlinepubs/7999959899/basedefs/std...