title: Speed of Golang Vs Java
body: <p>I have written a program in Java and equivalent in Go. My java program is taking around 5.95 seconds to execute while Go program is taking around 41.675789791 seconds. While speed of Go is comparable to C or C++ as it is compiled like C then Why this much of performance difference exists? Programs are as follows:</p>
  
  <p><strong>Go Program</strong></p>
  
  <pre><code>package main
  
  
  import (
      "math"
      "fmt"
      "time"
  )
  
  func main() {
      fmt.Printf("vvalue is %v", testFun(10, 16666611, 1000000000))
  }
  
  func fun(x float64) float64 {
      return math.Pow(x, 2) - x
  }
  
  func testFun(first float64, second float64, times int) float64 {
      var i = 0
      var result float64 = 0
      var dx float64
      dx = (second - first) / float64(times)
      for ; i &lt; times; i++ {
          result += fun(first + float64(i) * dx)
      }
      return result * dx
  }   
  </code></pre>
  
  <p><strong>Java Program</strong></p>
  
  <pre><code>public class Test {
  public static void main(String[] args) {
      Test test = new Test();
      double re = test.testFun(10, 16666611, 1000000000);
      System.out.println(re);
  }
  
  private double testFun(double first, double second, long times) {
      int i = 0;
      double result = 0;
      double dx = (second - first) / times;
      for (; i &lt; times; i++) {
          result += fun(first + i * dx);
      }
      return result * dx;
  }
  
  private double fun(double v) {
      return Math.pow(v, 2) - v;
  }
  }
  </code></pre>