バイナリ出力にバッファリングを適用したものを、今度は最適化有で実行してみよう。
結果は以下である。
Flat profile of 3.92 secs (250 total ticks): main Interpreted + native Method 0.4% 0 + 1 java.io.WinNTFileSystem.getBooleanAttributes 0.4% 0 + 1 java.io.WinNTFileSystem.canonicalize 0.8% 0 + 2 Total interpreted Compiled + native Method 6.8% 17 + 0 java.io.BufferedOutputStream.write 2.0% 5 + 0 java.io.FilterOutputStream.write 1.2% 3 + 0 Test.main 10.0% 25 + 0 Total compiled Stub + native Method 59.6% 0 + 149 java.io.FileOutputStream.writeBytes 59.6% 0 + 149 Total stub Thread-local ticks: 29.6% 74 Unknown: running frame Global summary of 3.92 seconds: 100.0% 250 Received ticks 29.6% 74 Unknown code
なんと、処理に掛かった時間はわずか約4秒である。
最適化無しの場合には比較的重い処理だったバッファリングが最適化され、負荷としてはほとんど無視できるほどまでになっている。
バッファリングしていないときにはjava.io.FileOutputStream.writeBytesに1000ticks以上費やしていたのに対し、この場合は150ticks程度に抑えられている。
Javaでのバッファリング処理は、入出力についてかなり効果的であることが分かった。
次は比較のために、Cの場合にも同様にバッファリング処理を用いて測定してみよう。