私はいくつかの(2k)単語をUserDictionaryに追加したいと思います。UserDictionaryに単語を挿入する最も速い方法
私はContentResolverの()で実験してきた。私は2Kを挿入するために100 3+分のバッチでbulkinsertをすれば自分の携帯電話で
// array of words
String[] words = getResources().getStringArray(R.array.word_array);
Long start,end = null;
start = System.currentTimeMillis();
int len = words.length;
ContentValues[] mValueArray = new ContentValues[len];
ContentValues mNewValues = new ContentValues();
mNewValues.put(UserDictionary.Words.APP_ID, "com.my.example");
mNewValues.put(UserDictionary.Words.LOCALE, "en");
mNewValues.put(UserDictionary.Words.FREQUENCY, "100");
for (int i = 0; i < len; ++i) {
mNewValues.put(UserDictionary.Words.WORD, words[i]);
mValueArray[i] = mNewValues;
}
getContentResolver().bulkInsert(
UserDictionary.Words.CONTENT_URI, // the user dictionary content URI
mValueArray // the values to insert
);
end = System.currentTimeMillis();
Toast toast = Toast.makeText(this, "Time for " + Integer.toString(len-1)+" words: " + Long.toString((end-start)) + "ms", 50);
toast.show();
約100msの単語ごとにかかります.... /一括挿入挿入言葉。
単語を挿入するためのより速い方法や、実行できる最適化について知っている人はいますか?
質問:UserDictionaryのサイズに上限がありますか、それは電話に依存していますか?
すべてのヘルプは、私は大規模なSQLクエリのためapplyBatch方法が使用されていることのAndroidのソースでのこぎりをしました
Michealster
applyBatchを試したところ、ほぼ同じ時間がかかるようです。意外にも、メソッドにかかわらず同じコードを実行するにはかなりのばらつき(〜+/- 10%)があります。 @PravinCGは基本的に、ラッパーに関係なく、ファイルの書き込みを高速化することはできません。 – user1094747