Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When compiled with gcc and g++ the only difference I see is within the first 4 lines.</p> <p>gcc:</p> <pre><code> .file "loops.c" .def ___main; .scl 2; .type 32; .endef .text .globl _main </code></pre> <p>g++:</p> <pre><code> .file "loops.c" .def ___main; .scl 2; .type 32; .endef .text .align 2 .globl _main </code></pre> <p>as you can see the only difference is that with g++, the alignment (2) occurs on a word boundary. This tiny difference seems to be making the significant performance difference.</p> <p>Here is a page explaining structure alignment, although it is for ARM/NetWinder it is still applicable as it discusses how alignment works on modern CPUs. You will want to read section 7 specifically "What are the disadvantages of word alignment?" :</p> <p><a href="http://netwinder.osuosl.org/users/b/brianbr/public_html/alignment.html" rel="nofollow noreferrer">http://netwinder.osuosl.org/users/b/brianbr/public_html/alignment.html</a></p> <p>and here is a reference on the .align operation:</p> <p><a href="http://www.nersc.gov/vendor_docs/ibm/asm/align.htm" rel="nofollow noreferrer">http://www.nersc.gov/vendor_docs/ibm/asm/align.htm</a></p> <p>Benchmarks as requested:</p> <p>gcc:</p> <pre><code>john@awesome:~$ time ./loopsC real 0m21.212s user 0m20.957s sys 0m0.004s </code></pre> <p>g++:</p> <pre><code>john@awesome:~$ time ./loopsGPP real 0m22.111s user 0m21.817s sys 0m0.000s </code></pre> <p>I reduced the inner-most iteration to 1200. Results aren't as widespread as I had hoped, but then again the assembly output was generated on windows, and the timings done in Linux. Maybe something different is done behind the scenes in MinGW than it is with gcc for Linux alignment-wise.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload