Possiedo un laptop con CPU Intel Core 2 Duo a 2,4 GHz e moduli DDR3 2x4 Gb a 1066 MHz.Il programma supera la velocità teorica di trasferimento della memoria
mi aspetto che questa memoria potrebbe funzionare a velocità 1067 MiB/sec, e fintanto che vi sono due canali, la velocità massima è 2134 MiB/sec (nel caso dispatcher memoria OS permetterà).
Ho fatto una piccola applicazione Java per verificare che:
private static final int size = 256 * 1024 * 1024; // 256 Mb
private static final byte[] storage = new byte[size];
private static final int s = 1024; // 1Kb
private static final int duration = 10; // 10sec
public static void main(String[] args) {
long start = System.currentTimeMillis();
Random rnd = new Random();
byte[] buf1 = new byte[s];
rnd.nextBytes(buf1);
long count = 0;
while (System.currentTimeMillis() - start < duration * 1000) {
long begin = (long) (rnd.nextDouble() * (size - s));
System.arraycopy(buf1, 0, storage, (int) begin, s);
++count;
}
double totalSeconds = (System.currentTimeMillis() - start)/1000.0;
double speed = count * s/totalSeconds/1024/1024;
System.out.println(count * s + " bytes transferred in " + totalSeconds + " secs (" + speed + " MiB/sec)");
byte[] buf2 = new byte[s];
count = 0;
start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < duration * 1000) {
long begin = (long) (rnd.nextDouble() * (size - s));
System.arraycopy(storage, (int) begin, buf2, 0, s);
Arrays.fill(buf2, (byte) 0);
++count;
}
totalSeconds = (System.currentTimeMillis() - start)/1000.0;
speed = count * s/totalSeconds/1024/1024;
System.out.println(count * s + " bytes transferred in " + totalSeconds + " secs (" + speed + " MiB/sec)");
}
mi aspettavo il risultato di essere sotto 2134 MiB/sec comunque ho ottenuto il seguente:
17530212352 bytes transferred in 10.0 secs (1671.811328125 MiB/sec)
31237926912 bytes transferred in 10.0 secs (2979.080859375 MiB/sec)
come è possibile quella velocità era di quasi 3 GiB/sec?
hai dimenticato la cache della CPU. c'è l1, l2 e anche cache l3 ... solo perché stai curiosando in modo casuale non significa che di tanto in tanto non riuscirai a ottenere un successo nella cache. –
la frequenza di clock di DDR non viene interpretata in questo modo ... – HuStmpHrrr
@MarcB Giusto sei. Ecco perché creo memoria buffer 256MiB. – Antonio