, RandomAccessFile.writeLong() . "rwd" "rw", , , . ( , , )
{
RandomAccessFile raf = new RandomAccessFile("test.dat", "rwd");
int longCount = 10000;
long start = System.nanoTime();
for (long l = 0; l < longCount; l++)
raf.writeLong(l);
long time = System.nanoTime() - start;
System.out.printf("writeLong() took %,d us on average%n", time / longCount / 1000);
raf.close();
}
{
RandomAccessFile raf = new RandomAccessFile("test2.dat", "rwd");
int longCount = 10000;
long start = System.nanoTime();
byte[] aux = new byte[8];
for (long l = 0; l < longCount; l++) {
aux[0] = (byte) (l >>> 56);
aux[1] = (byte) (l >>> 48);
aux[2] = (byte) (l >>> 40);
aux[3] = (byte) (l >>> 32);
aux[4] = (byte) (l >>> 24);
aux[5] = (byte) (l >>> 16);
aux[6] = (byte) (l >>> 8);
aux[7] = (byte) l;
raf.write(aux);
}
long time = System.nanoTime() - start;
System.out.printf("write byte[8] took %,d us on average%n", time / longCount / 1000);
raf.close();
}
writeLong() took 2,321 us on average
write byte[8] took 576 us on average
, . , 11 5400 /, 60000 /5400 = > 11 .