++iter
is most likely to be faster but never slower than iter++
.
Implementing the post increment operator iter++
needs to generate an additional temporary(this temporary is returned back while the original iter
is incremented ++
) over implementing the post increment operator ++iter
, So unless the compiler can optimize(yes it can) the post increment, then ++iter
will most likely be faster than iter++
.
Given the above, It is always preferable to use ++iter
in the looping conditions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…