雨谷の日和

過去20年で2,700を超えるアニメの第1話だけは見続けた僕のお勧めアニメがハズレなはずがない

Javaの文字列出力(バッファリング有/最適化有)

前回と同じ処理を、最適化有で実行してみよう。

Flat profile of 6.16 secs (394 total ticks): main

  Interpreted + native   Method                        
  1.0%     0  +     4    java.io.FileOutputStream.writeBytes
  0.3%     0  +     1    java.util.HashMap.put
  0.3%     0  +     1    java.security.BasicPermission.newPermissionCollection
  0.3%     1  +     0    java.lang.StringBuffer.
  1.8%     1  +     6    Total interpreted

     Compiled + native   Method                        
 45.2%   178  +     0    sun.io.CharToByteDoubleByte.convert
 15.5%    61  +     0    sun.io.CharToByteMS932.convSingleByte
  5.3%    21  +     0    java.io.PrintWriter.write
  4.1%    16  +     0    java.io.BufferedWriter.write
  3.0%    12  +     0    java.lang.String.getChars
  1.8%     7  +     0    Test.main
  0.5%     2  +     0    sun.nio.cs.StreamEncoder$ConverterSE.implWrite
 75.4%   297  +     0    Total compiled

         Stub + native   Method                        
  6.9%     0  +    27    java.io.FileOutputStream.writeBytes
  6.9%     0  +    27    Total stub

  Thread-local ticks:
  0.5%     2             Compilation
 15.5%    61             Unknown: running frame


Global summary of 6.16 seconds:
100.0%   394             Received ticks
  0.8%     3             Compilation
 15.5%    61             Unknown code

若干の性能向上があるが、それでも劇的な向上という感じではない。
バッファリングで、出力にかかる処理の効率は良くなっているが、やはり文字コード変換処理に時間がかかってしまっている。
最適化によって文字コード変換もかなり効率化されてはいるのだが、それでもまだ、処理の半分以上を占めている。
Javaを利用するに当たって、これは覚えておくべき事項の一つと言っていいだろう。