|
|
|
|
|||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Which is faster?
>Which is faster? Post Increment or assignment? Why?
Given two tasks, A and B, the C standard does not guarantee anything about the relative speed of the two, even if B is "repeat A one billion times". The result is also likely to depend on the instruction set of the target machine, and the optimization settings of this invocation of the compiler. In the case of post increment vs. assignment, it does matter whether the resulting value is used. The code for: p++; vs. p += 1; is hopefully identical. However, identical code does not guarantee identical performance, as the prior state of the cache and execution state of the processor may change that time. >I was not able to get any things. Those things belong to someone else, and scams with Paypal do not entitle you to take them. |
|
#2
|
|||
|
|||
|
Which is faster?
>In the case of post increment vs. assignment, it does matter
>whether the resulting value is used. The code for: >p++; >vs. >p += 1; >is hopefully identical. > >That's horribly misleading. I'd expect the compiler to generate >identical code for 'p += 1' and '++p', NT 'p++'. In fact, if the See those semicolons? They are in there for a reason. You can't use the value of p++; , an expression like foo(p++;) won't compile. >resulting value is used, the generated code HAS to be different >for 'p++' and 'p += 1'. Please explain how you can use the value with the semicolons left in. |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > Which is faster? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|