package jvm;

/**
 * it converts from python code
 * just check performance differences between python and java
 */
public class SpeedTest {

    public double calculate(int iter, int param1, int param2) {
        double result = 1.0;

        for (int i = 1; i <= iter; i++) {
            double jMinus = (double)i * param1 - param2;
            // Subtract 1.0 / jMinus from the result (use 1.0 for double division)
            result -= (1.0 / jMinus);

            // Calculate the second value of j
            double jPlus = (double)i * param1 + param2;
            // Add 1.0 / jPlus to the result
            result += (1.0 / jPlus);
        }

        return result;
    }

    public static void main(String[] args) {
        SpeedTest speedTest = new SpeedTest();
        long start = System.nanoTime();
        double result = speedTest.calculate(100_000_000, 4, 1) * 4.0;
        System.out.println(result);
        long end = System.nanoTime();
        long durationNanos = end - start;
        double durationSeconds = durationNanos / 1_000_000_000.0;
        System.out.println( durationSeconds );
    }
}
