Wednesday, August 27, 2008

pre-increment or post-increment?

Which is faster? Here it is quick and dirty - post-increment can never be faster than pre-increment, but can sometimes be slower. Why? There's an extra copy happening in the post-increment due to saving the value THEN incrementing. So, what would you prefer? C++ or ++C?

2 comments:

Hazar Tuna said...
This comment has been removed by the author.
Hazar Tuna said...

hey douche, we learned this sophomore year college, remember? nothing new :)

The question you are asking has the answer within itself; it's a matter of preference and application. If you are not sure what kind of performance the application needs, you can always monitor the assembly instructions being processed...