Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It appears that the RandomAccessFile.writeLong() doesn't minimise the number of calls to the OS. The cost increases dramatically by using "rwd" instead of "rw" which should be enough to indicate its not the calls themselves which cost the time. (its the fact the OS is try to commit every write to disk and the disk only spins so fast)</p> <pre><code>{ RandomAccessFile raf = new RandomAccessFile("test.dat", "rwd"); int longCount = 10000; long start = System.nanoTime(); for (long l = 0; l &lt; 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 &lt; longCount; l++) { aux[0] = (byte) (l &gt;&gt;&gt; 56); aux[1] = (byte) (l &gt;&gt;&gt; 48); aux[2] = (byte) (l &gt;&gt;&gt; 40); aux[3] = (byte) (l &gt;&gt;&gt; 32); aux[4] = (byte) (l &gt;&gt;&gt; 24); aux[5] = (byte) (l &gt;&gt;&gt; 16); aux[6] = (byte) (l &gt;&gt;&gt; 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(); } </code></pre> <p>prints</p> <pre><code>writeLong() took 2,321 us on average write byte[8] took 576 us on average </code></pre> <p>It would appear to me that you have no disk write caching on. Without disk caching, I would expect each commited write to take about 11 ms for a 5400 RPM disk ie 60000 ms/5400 => 11 ms.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload