title: Why is gccgo slower than gc in that particular case?
body: <p>I'm sure everyone knowing <code>golang</code> knows that <a href="http://blog.golang.org/2011/06/profiling-go-programs.html" rel="nofollow noreferrer">blog post</a> here. </p>
  
  <p>Reading it again, I wondered if using <code>gccgo</code> instead of <code>go build</code> would increase the speed a bit more. In my typical use case (scientific computations), a <code>gccgo</code>-generated binary is always faster than a <code>go build</code>-generated one.</p>
  
  <p>So, just grab this file: <a href="http://code.google.com/p/benchgraffiti/source/browse/havlak/havlak6.go" rel="nofollow noreferrer">havlak6.go</a> and compile it:</p>
  
  <pre><code>go build havlak6.go -O havlak6_go
  gccgo -o havlak6_gccgo -march=native -Ofast havlak6.go
  </code></pre>
  
  <p>Surprise !</p>
  
  <pre><code>$/usr/bin/time ./havlak6_go
  5.45user 0.06system 0:05.54elapsed 99%CPU
  
  $/usr/bin/time ./havlak6_gccgo
  11.38user 0.16system 0:11.74elapsed 98%CPU
  </code></pre>
  
  <p>I'm curious and want to know why an "optimizing" compiler does produce slower code.</p>
  
  <p>I tried to use <code>gprof</code> on <code>gccgo</code> generated binary:</p>
  
  <pre><code>gccgo -pg -march=native -Ofast havlak6.go
  ./a.out
  gprof a.out gmon.out
  </code></pre>
  
  <p>with no luck:</p>
  
  <pre><code>Flat profile:
  
  Each sample counts as 0.01 seconds.
   no time accumulated
  </code></pre>
  
  <p>As you can see the code has not been actually profiled.</p>
  
  <p>Of course, I read <a href="https://stackoverflow.com/questions/6816274/how-to-use-gprof-in-linux">this</a>, but as you can see, the program takes 10+ seconds to execute... The number of samples should be > 1000.</p>
  
  <p>I also tried:</p>
  
  <pre><code>rm a.out gmon.out
  LDFLAGS='-g -pg' gccgo -g -pg -march=native -Ofast havlak6.go
  ./a.out
  gprof
  </code></pre>
  
  <p>No success neither.</p>
  
  <p>Do you know what's wrong? Do you have an idea of why <code>gccgo</code>, with all its optimization routines fails to be faster than <code>gc</code> in this case?</p>
  
  <p><code>go</code> version: 1.0.2
  <code>gcc</code> version: 4.7.2</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Oh, I completely forgot to mention... I obviously tried pprof on the <code>gccgo</code>-generated binary... Here is a <code>top10</code>:</p>
  
  <pre><code>Welcome to pprof!  For help, type 'help'.
  (pprof) top10
  Total: 1143 samples
      1143 100.0% 100.0%     1143 100.0% 0x00007fbfb04cf1f4
         0   0.0% 100.0%      890  77.9% 0x00007fbfaf81101e
         0   0.0% 100.0%        4   0.3% 0x00007fbfaf8deb64
         0   0.0% 100.0%        1   0.1% 0x00007fbfaf8f2faf
         0   0.0% 100.0%        3   0.3% 0x00007fbfaf8f2fc5
         0   0.0% 100.0%        1   0.1% 0x00007fbfaf8f2fc9
         0   0.0% 100.0%        1   0.1% 0x00007fbfaf8f2fd6
         0   0.0% 100.0%        1   0.1% 0x00007fbfaf8f2fdf
         0   0.0% 100.0%        2   0.2% 0x00007fbfaf8f4a2f
         0   0.0% 100.0%        1   0.1% 0x00007fbfaf8f4a33
  </code></pre>
  
  <p>And that's why I'm looking for something else.</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>Since it seems that someone wants my question to be closed, I did not try to use <code>gprof</code> out of the blue: <a href="https://groups.google.com/d/msg/golang-nuts/1xESoT5Xcd0/bpMvxQeJguMJ" rel="nofollow noreferrer">https://groups.google.com/d/msg/golang-nuts/1xESoT5Xcd0/bpMvxQeJguMJ</a></p>