Android : How to add 1 milion items in Realm correctly?

on Monday, March 23, 2015


I want to choose between native SQLiteDatabase and Realm to deal with a big amount of data.


For benchmark I add to storage 1 milion of Product entities:


{id:integer,sku:string,name:string,data_creating:string}


Using SQLiteDatabase it takes near 1:34 min on my device.


Using Realm it takes more them 10 minutes.


My code is:



Realm realm = Realm.getInstance(getApplicationContext());
realm.beginTransaction();
for(int i = 0 ; i < 1000000;i++){
Product product = realm.createObject(Product.class);
product.setId(i+1);
product.setName("Product_"+i);
product.setSku("SKU__"+i);
product.setDateCreated(new Date());
}
realm.commitTransaction();


How can I improve my code for better time performance?


0 comments:

Post a Comment