4 ms·
Providing a semantically equivalent construct is a fair enough reason. > Furthermore, the difference between the two really is negligible. > ... > The differen
by vidarh 13y ago
Providing a semantically equivalent construct is a fair enough reason.
> Furthermore, the difference between the two really is negligible.
> ...
> The difference is an increment to a number, i.e. a single instruction which is probably the fastest instruction in the ISA.
Whether or not it matters will depend greatly on how often this loop is executed, and what else it does, and the ISA and available address modes, as well as whether or not the pointer and/or counter can fit in available registers.
If the pointer and counter is not in registers, and you don't have a suitable indirect indexed type load/test instruction, you can easily end up with 3+ extra memory reads. Memory access gets expensive if/when those kind of loops are run often enough.
I've seen speed improvements of 30%-50% from a couple of hours of work from production systems just from trivial rewrites to reduce memory accesses like these. Some fixes like that have paid my salary for months in reduction in server investments.