1. speed/optimization concerns

Alright, I'll admit, I'm somewhat anal retentive when it comes to optimizing my code and getting it to run fast without using more memory than it must, but I don't see that as a bad thing Anyway, I was wondering if anyone knows which would run faster (excuse the vague code, it's just meant as an example)

Code:
```int a()
{
return(42);
}```
Now, which b() is faster?

Code:
```int b()
{
int temp;

temp=a();
c(temp);
}```
or

Code:
```int b()
{
c(a());
}```
I'm guessing that the second one is, but I'm not sure, and I don't know exactly how the compiler changes the code around for optimizations and such... thanks.

2. What is c???
Generally, the second should be faster due to the declaration of a temporary variable. However, to be absolutely sure, compile both then use a disassembler to look at the assembly code.

3. Here's a disassembly of the C code, the 2nd b() looks faster !
Code:
```           int temp;
temp=a();

004010B8   call        @ILT+10(a) (0040100f)
004010BD   mov         dword ptr [ebp-4],eax

c(temp);

004010C0   mov         eax,dword ptr [ebp-4]
004010C3   push        eax
004010C4   call        @ILT+15(c) (00401014)
Code:
```           c(a());

00401108   call        @ILT+10(a) (0040100f)
0040110D   push        eax
0040110E   call        @ILT+15(c) (00401014)

4. First:

call - 19 clks
mov - 9 clks
mov - 9 clks
push - 11 clks
call - 19 clks

Sum: 70 clks

Second:

call - 19 clks
push - 11 clks
call - 19 clks

Sum: 52 clks

Conclusion:

The second is ~25% faster than the first.
The first is ~34% slower than the second.

PS:
I was really bored, I know .

5. Both *might* be of the same speed. Some compiler optimize real well and might put temp into a register and don't allocate it at all. That way, it'll be just as fast. Then there is always the VC++ calling technique: __fastcall. That could change the output assembly a bit.

Conclusion: It depends on the compiler and the compiler settings.

6. It heavily depends on compiler and optimization settings. Also, you should always try to find the bottlenecks of your program first and optimize that part, as a performance boost there might make your program visibly faster while a performance boost somewhere else might be wasted time.