Я тестирую производительность царства в Android.
если я вставлю 10000 данных в незашифрованную область, это будет стоить 16184 мс, в то время как стоимость зашифрованной области - 36000 мс. Это слишком медленно!
Является ли шифрование причиной этой ситуации? Как решить эту проблему?
Код SQLite:
ArrayList<ContentValues> valueArray = new ArrayList<>();
for (int i = 0; i < number; ++i) {
ContentValues value = new ContentValues();
value.put(PersonInfoTableEntry.COLUMN_NAME_DISPLAYINFO, list.get(i).getDisplayInfo());
value.put(PersonInfoTableEntry.COLUMN_NAME_DISPLAYPIC, list.get(i).getDisplayPic());
value.put(PersonInfoTableEntry.COLUMN_NAME_DISPLAYVERSION, list.get(i).getDisplayVersion());
value.put(PersonInfoTableEntry.COLUMN_NAME_FEATURE, list.get(i).getFaceFeatures());
value.put(PersonInfoTableEntry.COLUMN_NAME_FEATUREVERSION, list.get(i).getFeatureVersion());
value.put(PersonInfoTableEntry.COLUMN_NAME_PEOPLEVERSION, list.get(i).getPeopleVersion());
value.put(PersonInfoTableEntry.COLUMN_NAME_TIMESTAMPS, list.get(i).getTimestamp());
value.put(PersonInfoTableEntry.COLUMN_NAME_META, list.get(i).getMeta());
valueArray.add(value);
}
long startTime = System.currentTimeMillis();
Log.e(TAG, "StartTime Batch: " + "[" + number + "] " + startTime);
db.beginTransaction();
for (ContentValues contentValue: valueArray) {
long newRowId = db.insert(PersonInfoTableEntry.TABLE_NAME, null, contentValue);
}
db.setTransactionSuccessful();
db.endTransaction();
long endTime = System.currentTimeMillis();
Log.e(TAG, "EndTime Batch: " + "[" + number + "] " + endTime);
String str = "BatchWriteWithoutEncrypt [" + number + "] cost time : " + (endTime - startTime) + " ms";
Log.e(TAG, str);
Код Царства:
ArrayList<PersonInfo> list = new ArrayList<PersonInfo>();
Random rand = new Random();
for (int i = 0; i < number; ++i) {
PersonInfo tmpPersonInfo = new PersonInfo();
tmpPersonInfo.setDisplayInfo("测试" + rand.nextInt());
tmpPersonInfo.setDisplayPic(disPic + rand.nextInt());
RealmList<String> tmpStrList = new RealmList<>();
tmpStrList.add(featureStr);
tmpPersonInfo.setFaceFeatures(tmpStrList);
tmpPersonInfo.setDisplayVersion(md5);
tmpPersonInfo.setFeatureVersion(md5);
tmpPersonInfo.setMeta(md5);
list.add(tmpPersonInfo);
}
Log.e(TAG,"Array size is " + list.size());
long startTime = System.currentTimeMillis();
Log.e(TAG, "StartTime Batch: " + "[" + number + "] " + startTime);
realm.beginTransaction();
realm.insert(list);
realm.commitTransaction();
long endTime = System.currentTimeMillis();
Log.e(TAG, "EndTime Batch: " + "[" + number + "] " + endTime);
String str = "BatchWriteWithoutEncrypt [" + number + "] cost time : " + (endTime - startTime) + " ms";
Log.e(TAG, str);