Why is the following program 15% slower when compiling with g ++?

Updated: The actual resolution that the compilation field fulfilled my compilation request was different. In a slower instance, I ran code compiled on SuSE 9 but running on SuSE 10. There was enough difference for me to drop it and compare apples to apples. Using the same compilation unit, the results were as follows:

g ++ was about two percent slower

delta real 4 minutes delta user 4 months delta system 5 seconds

Thanks!

gcc v4.3 vs g ++ v4.3, reduced to the simplest case, used only simple flags

#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
    int i=0;
    int j=0;
    int k=0;
    int m=0;
    int n=0;
    for (i=0;i<1000;i++)
        for (j=0;j<6000;j++)
            for (k=0;k<12000;k++)
            {
                 m = i+j+k;
                 n=(m+1+1);
            }
    return 0;
}

? 15% . , . , .

: . SuSE 10.

+3
4

gcc g++ , , 4 .

:

    .file   "loops.c"
    .def    ___main;    .scl    2;  .type   32; .endef
    .text
.globl _main

++:

    .file   "loops.c"
    .def    ___main;    .scl    2;  .type   32; .endef
    .text
    .align 2
.globl _main

, , g++ (2) . , -, .

, , ARM/NetWinder - , , . 7, " ?"

http://netwinder.osuosl.org/users/b/brianbr/public_html/alignment.html

.align:

http://www.nersc.gov/vendor_docs/ibm/asm/align.htm

:

:

john@awesome:~$ time ./loopsC

real    0m21.212s
user    0m20.957s
sys 0m0.004s

++:

john@awesome:~$ time ./loopsGPP

real    0m22.111s
user    0m21.817s
sys 0m0.000s

1200. , , Linux. , - MinGW, gcc Linux.

+7

, , , , , . g++ - gcc.

+2

, gcc m n, .

:

m = i+j+k;
n = i+j+k+2; 

, 15%. . - 2 .

+1

, . , , .

(int argc, char** argv)
0

Source: https://habr.com/ru/post/1706155/


All Articles