I am learning Go and before this I have been using Java8. I wrote two programs to compare speed of execution between Java8 and Go.
The Java program ran in 604 seconds on and Go one took 2334.598334749 seconds. Can someone help me understand why Go program is running slow even when it is said to be faster.
➜ ~ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
➜ ~ go version
go version go1.12.4 darwin/amd64
//Java
public class Solution {
public static void main(String[] args) {
long start = System.currentTimeMillis();
for (int i = 0; i <= 1 * 1e8; i++) {
System.out.println(i);
}
long end = System.currentTimeMillis();
System.out.println(Duration.ofMillis(end - start).getSeconds());
}
}
//Golang
package main
import (
"fmt"
"time"
)
func main() {
var start = time.Now()
for i := 0; i<= 1 * 1e8 ;i++ {
fmt.Println(i)
}
fmt.Println(time.Now().Sub(start).Seconds())
}