This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Kojoley, rhettinger, serhiy.storchaka, vstinner
Date 2017-03-02.17:12:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488474728.28.0.500492347503.issue29698@psf.upfronthosting.co.za>
In-reply-to
Content
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...
History
Date User Action Args
2017-03-02 17:12:08vstinnersetrecipients: + vstinner, rhettinger, serhiy.storchaka, Kojoley
2017-03-02 17:12:08vstinnersetmessageid: <1488474728.28.0.500492347503.issue29698@psf.upfronthosting.co.za>
2017-03-02 17:12:08vstinnerlinkissue29698 messages
2017-03-02 17:12:08vstinnercreate