Tools:
VC 7.0
BCB 6.0
Compilation options: Maximum Speed Optimization (VC 7.0 turns off the automatic inline function option)
Decompilation tool: w32dasm
Benchmark Test procedure:
Void test ()
{
Int A = 0, B = 1, C = 4;
For (INT I = 0; I <B + C; ++ I ){
++;
}
}
Int main ()
{
_ ASM {
MoV edX, EDX
NOP
};
Test ();
}
Purpose: To test the program's ability to optimize useless functions. Because test does not return any value or modify any external variables,
Therefore, for programs, this is an invalid function, and a good compiler can optimize it.
VC compilation result:
// --------------------------------------------------- Main ()-----------------------
-
: 00401000 8bd2 mov edX, EDX
: 00401002 90 NOP
// Test (), very good !!!
: 00401003 C3 RET
// --------------------------------------------------- Main () finished --------------
BCB compilation result:
// ----------------------------------------------------- Main ()--------------
: 00401184 89d2 mov edX, EDX
: 00401186 90 NOP
: 00401187 e8dcffffff call 00401168 // call test (), bad !!!
: 0040118c 33c0 XOR eax, eax
: 0040118e C3 RET
// ----------------------------------------------------- Main () finished -------
From the above results, we can see that VC is quite good in this performance, and BCB is a little junk.
VC vs BCB === 1: 0
Benchmark Test Procedure
Int global = 0;
Int test ()
{
Int A = 0, B = 3, C = 4;
For (INT I = 0; I <B + C; ++ I ){
++;
++ Global;
}
Return global;
}
Int main ()
{
_ ASM {
MoV edX, EDX
NOP
};
Return test ();
}
Objective: To test the optimization capability of invalid variables in the function. A in the test () function is a useless variable and can be compiled effectively.
It should be optimized.
VC test results:
// ------------------------------------------------- Main ()--------------------
: 00401000 8bd2 mov edX, EDX
: 00401002 90 NOP
: 00401003 a1c0724000 mov eax, dword ptr [004072c0]
: 00401008 83c007 add eax, 00000007 //!!!!!!!!! Terror !!!!
: 0040100b a3c0724000 mov dword ptr [004072c0], eax
: 00401010 C3 RET
// ------------------------------------------------ Main () finished ----------
--
BCB test results
// ----------------------------------------------- Main ()-------------------
: 0040118c 89d2 mov edX, EDX
: 0040118e 90 NOP
: 0040118f e8d4ffffff call 00401168 // bad
: 00401194 C3 RET
// ----------------------------------------------- Main () finished ----------
// ---------------------------------------------- Test ()----------------------
: 00401168 53 push EBX
: 00401169 ba03000000 mov edX, 00000003 // B = 3
: 0040da-e b904000000 mov ECx, 00000004 // C = 4
: 00401173 33c0 XOR eax, eax // I = 0
: 00401175 eb07 JMP 0040117e
: 00401177 ff05a4204000 Inc dword ptr [004020a4] // ++ global
: 0040117d 40 Inc eax // ++ I
// No ++ A; good !!!
: 0040117e 8d1c11 Lea EBX, dword ptr [ECx + EDX] // EBX = B + C =
7
: 00401181 3bc3 CMP eax, EBX
: 00401183 7cf2 JL 00401177
: 00401185 a1a4204000 mov eax, dword ptr [004020a4]
: 0040118a 5B pop EBX
: 0040118b C3 RET
// -------------------------------------------- Test () finished --------------
Result summary:
The performance of VC on this item is terrible. It is optimized from the program logic and directly calculated.
The global value is then directly embedded into main (). The Compiler shown here is quite intelligent !!!
The performance of BC on this item is quite satisfactory compared with VC! First, the main () function calls test () as usual ()
In test (), BCB shows some advanced optimization methods. First, it does not calculate the conditional variable B + C multiple times,
Instead, it is stored in edX after one computation, avoiding computing condition variables during each loop,
Secondly, the invalid variable A is optimized. In general, it is not satisfactory, but compared with VC, it is actually a world.
No, the VC execution program is more efficient than BCB!
It seems that VC's progress in compiler technology is crazy after joining MS from Anders, while BCB
It lags behind too much ~~~ 55555 ~~~~
However, It is shown from one side that manual optimization can be performed manually, because you cannot know if every Compilation
Devices can be smart enough ~~~
Http://purec.binghua.com/Article/ShowArticle.asp? ArticleID = 230