use of sqlite.feature.speed.persistence.BindPersonDataSource.Transaction in project kripton by xcesco.
the class TestSpeedRuntime method testInsertBatch.
@Test
public void testInsertBatch() {
final int ITEM_COUNTER = 10000;
final One<Long> start = new One<>();
final One<Long> end = new One<>();
final One<Integer> index = new One<>();
final int COUNTER = 100;
final BindPersonDataSource ds = BindPersonDataSource.instance();
ds.openWritableDatabase();
final List<Person> list = new ArrayList<Person>();
for (int i = 0; i < ITEM_COUNTER; i++) {
Person bean = new Person();
bean.name = "name" + index.value0;
bean.surname = "surname" + index.value0;
list.add(bean);
}
start.value0 = System.currentTimeMillis();
for (int i = 0; i < COUNTER; i++) {
index.value0 = i;
ds.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
PersonDaoImpl dao = daoFactory.getPersonDao();
for (int i = 0; i < list.size(); i++) {
dao.insert(list.get(i));
}
return TransactionResult.COMMIT;
}
});
}
end.value0 = System.currentTimeMillis();
ds.close();
// 3100
System.out.println("Average time to insert " + ITEM_COUNTER + " items: " + ((end.value0 - start.value0) * 1.0 / COUNTER) + " ms");
}
use of sqlite.feature.speed.persistence.BindPersonDataSource.Transaction in project kripton by xcesco.
the class TestSpeedRuntime method testTransaction.
@Test
public void testTransaction() {
final One<Long> start = new One<>();
final One<Long> end = new One<>();
final One<Integer> index = new One<>();
final int COUNTER = 2000;
final BindPersonDataSource ds = BindPersonDataSource.instance();
ds.openWritableDatabase();
start.value0 = System.currentTimeMillis();
for (int i = 0; i < COUNTER; i++) {
index.value0 = i;
ds.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
PersonDaoImpl dao = daoFactory.getPersonDao();
Person bean = new Person();
bean.name = "name" + index.value0;
bean.surname = "surname" + index.value0;
// Object bean = new
dao.insert(bean);
return TransactionResult.COMMIT;
}
});
}
end.value0 = System.currentTimeMillis();
ds.close();
// 3100
System.out.println("Esecuzione terminata in " + (end.value0 - start.value0) + " ms");
}
use of sqlite.feature.speed.persistence.BindPersonDataSource.Transaction in project kripton by xcesco.
the class TestSpeedRuntime method testSingle.
@Test
public void testSingle() {
final One<Long> start = new One<>();
final One<Long> end = new One<>();
final int COUNTER = 200000;
final BindPersonDataSource ds = BindPersonDataSource.instance();
ds.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
start.value0 = System.currentTimeMillis();
PersonDaoImpl dao = daoFactory.getPersonDao();
for (int i = 0; i < COUNTER; i++) {
Person bean = new Person();
bean.name = "name" + i;
bean.surname = "surname" + i;
// Object bean = new
dao.insert(bean);
}
end.value0 = System.currentTimeMillis();
return TransactionResult.COMMIT;
}
});
// 3100
System.out.println("Esecuzione terminata in " + (end.value0 - start.value0) + " ms");
}
Aggregations