C for loop indexing: is forward-indexing faster in new CPUs?

后端 未结 7 2114
抹茶落季
抹茶落季 2020-12-01 09:57

On a mailing list I\'m subscribed to, two fairly knowledgeable (IMO) programmers were discussing some optimized code, and saying something along the lines of:

7条回答
  •  孤街浪徒
    2020-12-01 10:22

    It probably doesn't make a hoot of difference speed-wise, but I often write:

    for (i = n; --i >= 0; ) blah blah
    

    which I think at one time generated cleaner assembly.

    Of course, in answering this kind of question, I run the risk of affirming that this is important. It's a micro-optimization kind of question, which is closely related to premature optimization, which everybody says you shouldn't do, but nevertheless SO is awash in it.

提交回复
热议问题