Geschwindigkeit von Golang vs. JavaJava

Java-Forum
Anonymous
 Geschwindigkeit von Golang vs. Java

Post by Anonymous »

Ich habe ein Programm in Java und ein entsprechendes Programm in Go geschrieben. Die Ausführung meines Java-Programms dauert etwa 5,95 Sekunden, während das Go-Programm etwa 41,675789791 Sekunden benötigt. Während die Geschwindigkeit von Go mit der von C oder C++ vergleichbar ist, da es wie C kompiliert wird, warum gibt es dann so große Leistungsunterschiede? Die Programme sind wie folgt:

Go-Programm

Code: Select all

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 < times; i++ {
result += fun(first + float64(i) * dx)
}
return result * dx
}
Java-Programm

Code: Select all

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 < times; i++) {
result += fun(first + i * dx);
}
return result * dx;
}

private double fun(double v) {
return Math.pow(v, 2) - v;
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post