title: C++ vs Java speed(Loops with Arithmetic)
body: <p>The following small programs which compute the sum of all numbers from 1 to 1 billion we're written in C++ and Java as closely as I could write them. My understanding is that C++ is the "faster" language, but the java version of this code completes in ~.5 seconds vs ~3 seconds for C++. </p>
  
  <p>C++ (GCC Compiler):</p>
  
  <pre><code>int main(){
      long long x = 0;
      for (long i=0;i&lt;1000000001;i++){
      x=x+i;
      }
      cout &lt;&lt; x &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>JAVA:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args)  {
          long x=0;
          for (long i=0;i&lt;1000000001;i++){
              x=x+i;
          }
          System.out.println(x);
  
      }
  
  }
  </code></pre>
  
  <p>How would one optimize the C++ code to be as fast as the JAVA version? Is it even possible?</p>