I'm trying to compare Realm with Snappydb (This is my repo for those who would like to have a look at benchmark). I guess my way is wrong, as store-to-db time takes super long time in Realm in compare with Sanppydb.
Benchmark shows following result. As you can see in the image, Realm is around 100-200 times slower than Snappydb.
What I'm doing is creating 10,000 objects first and then storing them into the db. So, in my code I store a Booking object in this way (there is a for loop that iterates 10,000 times):
public void storeBooking(final Booking booking) {
mRealm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Booking realmBooking = realm.createObject(Booking.class);
realmBooking.setId(booking.getId());
realmBooking.setCode(booking.getCode());
realmBooking.setFareLowerBound(booking.getFareLowerBound());
realmBooking.setFareUpperBound(booking.getFareUpperBound());
realmBooking.setPhoneNumber(booking.getPhoneNumber());
realmBooking.setPickUpTime(booking.getPickUpTime());
realmBooking.setRequestedTaxiTypeName(booking.getRequestedTaxiTypeName());
realmBooking.setTaxiTypeId(booking.getTaxiTypeId());
}
});
}
Update
This is Snappydb method for storing Booking object.
public void storeBooking(final String key, final Booking booking) {
try {
mSnappyDb.put(key, booking);
} catch (SnappydbException e) {
e.printStackTrace();
}
}
Update
New results using insertOrUpdate()
method and one transaction
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…