STINNER Victor added the comment:

The purpose of the issue is unclear to me. Why do you want to replace while 
with for? For readability?

I agree that "n++; while (--n) ..." is surprising. It seems strange to start 
with a "n++" to decrement it in the next instruction :-) It's also unusual to 
write loops like that.


> I have failed to find previous discussion when `while (n--)` was changed to 
> `n++; while (--n)`.

You should ask Raymond Hettinger for the rationale. The commit message says 
"better generated code (on both GCC and CLang)", but there is no benchmark nor 
any data to validate this.


> I have made a benchmark.

Nowadays, C compilers are very smart and implement crazy optimizations. Python 
releases are compiled using PGO, or even PGO+LTO. Please compile your benchmark 
using PGO. I expect that compilers emit the same machine code at the end for 
"while" and "for" loops.

The question is also if your benchmark is revelant for the _collections module.

What should I see in your benchmark? I see that results are the same for while 
and for_loop except a minor noise in the benchmark.

--

I also dislike spending time on such minor micro-optimization...

----------
nosy: +haypo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29698>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to