PCスペック
Windows10 HOME 64bit
メモリ 32GB
プロセッサ Intel Core i7-8700CPU 3.20GHz
Android Studio 3.4.1
デモ用端末(XPERIA OS:7.0 API 24)
プログラム中にいくつかのfor文で繰り返し処理を行うと,同じfor文でも処理速度が速いときと遅いときが存在します.
以下がfor文が開始された時のlogcatの表示です.
2019-08-05 11:03:09.902 19664-19669/com.example.csv I/art: Do full code cache collection, code=65KB, data=85KB
2019-08-05 11:03:09.903 19664-19669/com.example.csv I/art: After code cache collection, code=50KB, data=68KB
2019-08-05 11:03:09.904 19664-19669/com.example.csv I/art: JIT allocated 54KB for stack maps of void com.example.csv.MainActivity.match(java.lang.String)
2019-08-05 11:03:09.977 19664-19669/com.example.csv I/art: Do partial code cache collection, code=50KB, data=68KB
2019-08-05 11:03:09.977 19664-19669/com.example.csv I/art: After code cache collection, code=50KB, data=68KB
2019-08-05 11:03:09.977 19664-19669/com.example.csv I/art: Increasing code cache capacity to 512KB
2019-08-05 11:03:09.980 19664-19669/com.example.csv I/art: Compiler allocated 10MB to compile void com.example.csv.MainActivity.match(java.lang.String)
2019-08-05 11:03:10.051 19664-19669/com.example.csv I/art: JIT allocated 54KB for stack maps of void com.example.csv.MainActivity.match(java.lang.String)
2019-08-05 11:03:10.054 19664-19669/com.example.csv I/art: Compiler allocated 11MB to compile void com.example.csv.MainActivity.match(java.lang.String)
上記のようなlogが表示されると必ずと言っていいほど,for文の処理時間が長くなってしまいます.
System.currentTimeMillis();で時間を計測すると,10倍以上処理時間に差が出ます.
また,メソッド内で通るfor文が1個の時だと処理が速いのですが,
for文が2個あるときは,どちらか片方の処理が遅くなる場合があります.
処理時間が長くなってしまうことで, Skipped 996 frames!のように,その後の処理が実行されずに飛ばされてしまう弊害も起きてしまうので,なんとかしたいです.
java
1 //入力された日本語と適合する日本語を探して、対応する言語を表示するメソッド 2 public void match(String text) { 3 4 5 int matchCount = 0; 6 7 for (int j = 0; j < timeList.size(); j++) {//CSVの要素を回す 8 if (timeList.get(j).startsWith(text)) {//前方一致したら 9 textView.setText(timeList.get(j)); 10 matchCount++; 11 break; 12 } 13 } 14 15 16 //~~~~~~~~~~~ 17 18 if(matchCount == 1) { 19 for (int c = 0; c < tempList.size(); c++) {//CSVの要素を回す 20 if (tempList.get(c).equals(temp)) {//完全一致 21 textView.setText(timeList.get(j)); 22 break; 23 } 24 } 25 } 26 27 28 } 29
これを直す方法はあるのでしょうか?
回答1件
あなたの回答
tips
プレビュー