4 ms·
On IA-32, a decrementing-until-zero loop gets its own instruction (called—unsurprisingly—LOOP.) If it optimized in that one case, it would take microseconds to
by derefr 16y ago
On IA-32, a decrementing-until-zero loop gets its own instruction (called—unsurprisingly—LOOP.) If it optimized in that one case, it would take microseconds to execute the whole test, which would show up as 0ms.
- prodigal_erik 16y agoIsn't LOOP one of those microcoded instructions that actually runs slower on modern processors than a RISC-style separate decrement and compare?
- derefr 16y agoIt's a slow instruction, but it's a single instruction—in a loop with an empty body, this creates the best possible situation for memory locality: you just keep reading the same memory address/cache line over and over.