title: Why gcc's output much slower than Visual Studio's (for this code)?
body: <p>When I compile the followning code on a regularly updated Ubuntu 16.04 64bit using gcc by</p>
  
  <pre><code>gcc source.c -O3 --fast-math
  </code></pre>
  
  <p>the executable file takes about 45 seconds of CPU time to run. But on the same machine and in Windows 7 64bit, using Visual Studio 2012 in release mode, it takes less than 10 seconds of CPU time to run. What is the main cause of this difference? Haven't I used enough optimization options of gcc? Is Visual Studio's compiler a better one? Or something else?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;time.h&gt;
  
  #define Nx 1000
  
  int main()
  {
      double d = 0.015e-2;        // meter
      double V0 = 400;            // volt
      double De = 1800e-4;        // m^2 per sec
      double mu_e = 2.9e1 / 760;  // m^2 per volt sec
      double n0 = 1e19;           // per m^3
      double e_eps = 1.602e-19 / 8.854e-12;
      double ne[Nx], je[Nx], E[Nx];
      double dx = d / (Nx - 1);
      double dt = 1e-14;          // s
      const int Nt = 500000;
      int i, k;
      double sum;
      FILE *fp_ne, *fp_E;
      double alpha, exp_alpha, R;
      int ESign = -1;
      clock_t start_t, end_t;
  
      start_t = clock();
      // initialization
      for (i = 1; i &lt; Nx; i++)
          ne[i] = n0;
      ne[0] = 1e-4 * n0;
  
      for (i = 0; i &lt; Nx; i++)
          E[i] = -V0 / d;
  
      // time loop
      for (k = 0; k &lt; Nt; k++)
      {
          if (k%1000==0) printf("k = %d\n", k);
          for (i = 0; i &lt; (Nx-1); i++)
          {
              alpha = mu_e*dx*E[i]/De;
              exp_alpha = exp(alpha);
              R = (exp_alpha-1)/alpha;
              je[i] = (De/(dx*R))*(ne[i]-exp_alpha*ne[i+1]);
          }
  
          for (i = 1; i &lt; (Nx - 1); i++)
              ne[i] += -dt/dx*(je[i] - je[i-1]);
          ne[Nx - 1] = ne[Nx - 2];
  
          sum = 0;
          for (i = 0; i &lt; (Nx - 1); i++)
              sum += dx*je[i];
          for (i = 0; i &lt; (Nx - 1); i++)
          {
              E[i] += -dt*e_eps*(sum / d - je[i]);
              if (E[i]&gt;=0) ESign=+1;
          }
          if (ESign==1) break;
      }
  
      // output
      printf("time=%e\n",k*dt);
      fp_ne = fopen("ne.txt", "w");
      fp_E = fopen("E.txt", "w");
      fprintf(fp_ne, "# x (cm)\tne(per cm^3)\n");
      fprintf(fp_E,  "# x (cm)\tE(V/cm)\n");
      for (i = 0; i &lt; Nx; i++)
          fprintf(fp_ne, "%f\t%e\n", i*dx*100,ne[i]/1e6);
      for (i = 0; i &lt; Nx-1; i++)
          fprintf(fp_E, "%f\t%e\n", i*dx*100, fabs(E[i])/1e2);
      fclose(fp_ne);
      fclose(fp_E);
      end_t = clock();
      printf("CPU time = %f\n", (double)(end_t - start_t) / CLOCKS_PER_SEC);
  }
  </code></pre>