mio mini punto di riferimento:tempo Moltiplicazione in BigInteger
import java.math.*;
import java.util.*;
import java.io.*;
public class c
{
static Random rnd = new Random();
public static String addDigits(String a, int n)
{
if(a==null) return null;
if(n<=0) return a;
for(int i=0; i<n; i++)
a+=rnd.nextInt(10);
return a;
}
public static void main(String[] args) throws IOException
{
int n = 10000; \\number of iterations
int k = 10; \\number of digits added at each iteration
BigInteger a;
BigInteger b;
String as = "";
String bs = "";
as += rnd.nextInt(9)+1;
bs += rnd.nextInt(9)+1;
a = new BigInteger(as);
b = new BigInteger(bs);
FileWriter fw = new FileWriter("c.txt");
long t1 = System.nanoTime();
a.multiply(b);
long t2 = System.nanoTime();
//fw.write("1,"+(t2-t1)+"\n");
if(k>0) {
as = addDigits(as, k-1);
bs = addDigits(as, k-1);
}
for(int i=0; i<n; i++)
{
a = new BigInteger(as);
b = new BigInteger(bs);
t1 = System.nanoTime();
a.multiply(b);
t2 = System.nanoTime();
fw.write(((i+1)*k)+","+(t2-t1)+"\n");
if(i < n-1)
{
as = addDigits(as, k);
bs = addDigits(as, k);
}
System.out.println((i+1)*k);
}
fw.close();
}
}
Misura tempo moltiplicazione di n cifre BigInteger
Risultato:
Si può facilmente vedere il trend, ma perché c'è così grande rumore superiore a 50000 cifre? È a causa del garbage collector o c'è qualcos'altro che influenza i miei risultati? Durante l'esecuzione del test, non c'erano altre applicazioni in esecuzione.
Risultato dal test con solo cifre dispari. Il test è stato più breve (n = 1000, k = 100)
cifre dispari (n = 10000, k = 10)
Come potete vedere c'è un enorme rumore tra 65000 e 70000. mi chiedo perché ...
cifre dispari (n = 10000, k = 10), System.gc()
ogni 1000 iterazioni Risultati in rumore tra 50000-70000
Non c'è modo di sapere con le informazioni che hai mostrato. Perché non provi un 'System.gc()' ogni iterazioni da 500-1000 per vedere se lo liscia. – hvgotcodes
"Non c'erano altre applicazioni in esecuzione." Sei in un ambiente di elaborazione in tempo reale senza un sistema operativo time-sharing (come Windows)? È impossibile garantire che ogni ciclo della CPU venga assegnato solo alla tua applicazione. – mellamokb
Sry per essere fuori tema ma, con quale programma stai pianificando? – keyser