Additional comparion between java and pypy only, basic sum in a loop with bignits, no Miller Rabin. Python code first:
%%writefile bigint_java_vs_pypy.py
def sum_of_prime_forth_powers(n):
sum = 0
i = 2
while i <= n:
if True:
sum += i *i * i * i
i += 1
else:
i += 1
return sum
print(sum_of_prime_forth_powers(1000000))
Overwriting bigint_java_vs_pypy.py
Java code:
! cat Bigint_sum.java
import java.lang.Math.*; import java.math.BigInteger; import java.util.*; public class Bigint_sum { public static BigInteger sum_of_forth_power_primes(long n) { long i = 2; BigInteger SUM = BigInteger.ZERO; while (i <= n) { BigInteger tmp = BigInteger.valueOf(i); if (true) { SUM = SUM.add(tmp.multiply(tmp.multiply(tmp.multiply(tmp)))); i += 1; } else i += 1; } return SUM; } public static void main(String [] args) { System.out.println(sum_of_forth_power_primes(1000000).toString()); } }
! javac Bigint_sum.java
Tests:
%timeit ! java Bigint_sum
200000500000333333333333299999 200000500000333333333333299999 200000500000333333333333299999 200000500000333333333333299999 1 loop, best of 3: 347 ms per loop
%timeit ! pypy bigint_java_vs_pypy.py
200000500000333333333333299999 200000500000333333333333299999 200000500000333333333333299999 200000500000333333333333299999 1 loop, best of 3: 252 ms per loop
Results:
While java is faster with longs, pypy wins when bigints comes into the play.