Many processors have "small" instructions which can perform arithmetic operations, including comparisons, on certain immediately-specified operands. Operands other than those special values must either use a larger instruction format or, in some cases, must use a "load value from memory" instruction. In the ARM Cortex-M3 instruction set, for example, there are at least five ways a value might be compared to a constant:
cmp r0,#1 ; One-word instruction, limited to values 0-255
cmp r0,#1000 ; Two-word instruction, limited to values 0-255 times a power of 2
cmn r0,#1000 ; Equivalent to comparing value with -1000
; Two-word instruction, limited to values 0-255 times a power of 2
mov r1,#30000 ; Two words; can handle any value 0-65535
cmp r0,r1 ; Could use cmn to compare to values -1 to -65535
ldr r1,[constant1000000] ; One or two words, based upon how nearby the constant is
The first form is the smallest; the second and third form may or may not execute as quickly, depending upon the speed of the memory from which code is fetched. The fourth form form will almost certainly be slower than the first three, and the fifth form even slower, but the latter can be used with any 32-bit value.
On older x86 processors, short-form compare instructions would execute faster than long-form ones, but many newer processors will convert both the long and short forms to the same representation when they are first fetched, and store that uniform representation in the cache. Thus, while embedded controllers (like those found on many mobile platforms) will have a speed difference, many x86-based computers won't.
Note also that in many cases where a constant is used heavily within a loop, a compiler will only need to load the constant into a register once--before the loop starts--rendering timing distinctions moot. On the other hand, there are some situations, even in small loops, where that won't always happen; if a loop is small but heavily-executed, there occasionally may be a major performance between comparisons involving short immediate values and those involving longer ones.