[Edu-sig] Fwd: Which way did the chicken cross the road?

Tim Peters tim.one@comcast.net
Mon, 14 Oct 2002 00:53:23 -0400


[Danny Yoo]
> This reminds me of the electrifying shock I felt when I read through
> snippets of code in TAOCP: in almost all of his inner loops, the index
> variable decrements from n to 0, rather than from 0 to n.  The reason was
> that a comparison against zero was slightly faster than a comparison
> between arbitrary numbers!

Many C loops in Python's implementation are written the same way, for the
same reason.  In fact, the HW you're probably using automatically sets a
"was the result 0?" flag on every subtraction, so that no explicit
comparison instruction is needed then.  There's nothing like learning
assembly language for helping you to focus on the wrong things <wink>.

the-world-would-be-a-better-place-if-uncle-don-used-python-ly y'rs
    = tim