現在、Android アプリケーションの一部として配列にインポートしているかなり大きな CSV ファイル (~.5Mb、16000 行、6 列) があります。CSV を assets フォルダーに保存し、使用するたびに再インポートします。現在、インポートには 7 ~ 8 秒かかります (1 行あたり約 0.47 ミリ秒)。
CSVを読み込むために使用しているコードは次のとおりです。
@Override
protected ArrayList<Car> doInBackground(Void... voids) {
ArrayList<Car> toReturn = new ArrayList<Car>();
try {
BufferedReader CSVFile = new BufferedReader(new InputStreamReader(CarChooser.this.getAssets().open(CSV_NAME)));
String dataRow = CSVFile.readLine();
Car car;
while (dataRow != null){
// split on the comma only if that comma has zero, or an even number of quotes in ahead of it
String[] dataArray = dataRow.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
if(dataArray.length != 6) throw new IllegalStateException("Row length should be 6. Row length = " + dataArray.length);
int year = Integer.parseInt(dataArray[0]);
String make = Utils.removeQuotes(dataArray[1]);
String model = Utils.removeQuotes(dataArray[2]);
float mpgCty = Float.parseFloat(dataArray[3]);
float mpgHwy = Float.parseFloat(dataArray[4]);
float mpgCmb = Float.parseFloat(dataArray[5]);
car = new Car(year, make, model, mpgCty, mpgHwy, mpgCmb);
toReturn.add(car);
dataRow = CSVFile.readLine();
}
CSVFile.close();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return toReturn;
}
ここに私の質問があります:
私が期待すべき時間はかかりますか?
そうでない場合、なぜそんなに時間がかかるのですか?
このプロセス全体をスピードアップする最善の方法は何ですか?
私は SQL データベースの経験がありませんが、検討する必要があるように思えます。