3 ms·
It makes sense that a zero comparison is faster, but 0ms does seem strange. It's 31ms for a basic for loop on the same platform, whereas in Safari the times are
by austintaylor 16y ago
It makes sense that a zero comparison is faster, but 0ms does seem strange. It's 31ms for a basic for loop on the same platform, whereas in Safari the times are 2ms and 5ms respectively, which seems a lot more reasonable.
Is it possible that IE 7 is deleting the whole loop as a no-op?
- derefr 16y agoOn 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.