@Override public boolean onCreate() { // if(daoSession == null) { // throw new IllegalStateException("DaoSession must be set before content provider is created"); // } DaoLog.d("Content Provider started: " + CONTENT_URI); return true; }
public void logStats() { int collisions = 0; for (Entry<T> entry : table) { while (entry != null && entry.next != null) { collisions++; entry = entry.next; } } DaoLog.d("load: " + ((float) size) / capacity + ", size: " + size + ", capa: " + capacity + ", collisions: " + collisions + ", collision ratio: " + ((float) collisions) / size); }
public static void logTableDump(SQLiteDatabase db, String tablename) { Cursor cursor = db.query(tablename, null, null, null, null, null, null); try { String dump = DatabaseUtils.dumpCursorToString(cursor); DaoLog.d(dump); } finally { cursor.close(); } }
protected boolean checkKeyIsNullable() { if (createEntity(null) == null) { DaoLog.d("Test is not available for entities with non-null keys"); return false; } return true; }
public void logStats() { int collisions = 0; for (Entry entry : table) { while (entry != null && entry.next != null) { collisions++; entry = entry.next; } } DaoLog.d("load: " + ((float) size) / capacity + ", size: " + size + ", capa: " + capacity + ", collisions: " + collisions + ", collision ratio: " + ((float) collisions) / size); }
public void testHashMapPerformance() { // runTests(100); // runTests(1000); // runTests(10000); // runTests(100000); // hash: 1485/420ms; sparse: 148196/196ms DaoLog.d("testHashMapPerformance DONE"); }
protected void stopClock(String extraInfoOrNull) { long time = System.currentTimeMillis() - start; String extraLog = extraInfoOrNull != null ? " (" + extraInfoOrNull + ")" : ""; DaoLog.d(traceName + " completed in " + time + "ms" + extraLog); }
public void testSetIntPerf() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { int count = 100000; long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { setIntValue(i); } long time = System.currentTimeMillis() - start; Method method = getClass().getMethod("setIntValue", int.class); long start2 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { method.invoke(this, i); } long time2 = System.currentTimeMillis() - start2; DaoLog.d("set int: normal=" + time + "ms, reflected=" + time2 + "ms, " + 1000 * count / time2 + " refelected ops/s, slower=" + ((float) time2) / time); }
public void testGetIntPerf() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { int count = 100000; long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { int x = getIntValue(); } long time = System.currentTimeMillis() - start; Method method = getClass().getMethod("getIntValue"); long start2 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { int x = (Integer) method.invoke(this); } long time2 = System.currentTimeMillis() - start2; DaoLog.d("get int: normal=" + time + "ms, reflected=" + time2 + "ms, " + 1000 * count / time2 + " refelected ops/s, slower=" + ((float) time2) / time); }
private File getBenchFile(String name) { File dir = Environment.getExternalStorageDirectory(); File file = new File(dir, name); if (dir == null || !dir.canWrite()) { Application app = createApplication(Application.class); File appFile = new File(app.getFilesDir(), name); DaoLog.d("Using file " + appFile.getAbsolutePath() + ", (cannot write to " + file.getAbsolutePath() + ")"); file = appFile; } return file; }
private void runTests(int count, boolean randomKeys) { DaoLog.d("-----------------------------------"); DaoLog.d("Look up " + count + (randomKeys ? " random" : " linear") + " keys on " + new Date()); DaoLog.d("-----------------------------------"); long[] keys = new long[count]; for (int i = 0; i < count; i++) { if (randomKeys) { keys[i] = random.nextLong(); } else { keys[i] = i; } } for (int i = 0; i < 3; i++) { runMapTest(new HashMap<Long, Object>(count), keys, "hashmap"); // runMapTest(new WeakHashMap<Long, Object>(count), keys, "weakhashmap"); // runMapTest(new ConcurrentHashMap<Long, Object>(count), keys, "concurrent-hashmap"); // runLongSparseArrayTest(keys); runLongHashMap(keys); runLongHashMapAmarena2DZechnerTest(keys); // runLongHashMapJDBMTest(keys); DaoLog.d("-----------------------------------"); } }
@Override protected void setUp() throws Exception { super.setUp(); DaoLog.d("####################"); DaoLog.d(getClass().getSimpleName() + ": " + BATCH_SIZE + " entities on " + new Date()); DaoLog.d("####################"); clearIdentityScopeIfAny(); entities = new ArrayList(BATCH_SIZE); for (int i = 0; i < BATCH_SIZE; i++) { entities.add(createEntity()); } dao.deleteAll(); }
public void testSetStringPerf() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { int count = 100000; long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { setStringValue("the quick brown fox"); } long time = System.currentTimeMillis() - start; Method method = getClass().getMethod("setStringValue", String.class); long start2 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { method.invoke(this, "the quick brown fox"); } long time2 = System.currentTimeMillis() - start2; DaoLog.d("set String: normal=" + time + "ms, reflected=" + time2 + "ms, " + 1000 * count / time2 + " refelected ops/s, slower=" + ((float) time2) / time); }
public void testGetStringPerf() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { int count = 100000; long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { String x = getStringValue(); } long time = System.currentTimeMillis() - start; Method method = getClass().getMethod("getStringValue"); long start2 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { String x = (String) method.invoke(this); } long time2 = System.currentTimeMillis() - start2; DaoLog.d("get String: normal=" + time + "ms, reflected=" + time2 + "ms, " + 1000 * count / time2 + " refelected ops/s, slower=" + ((float) time2) / time); } }
public void testAssignPk() { if (daoAccess.isEntityUpdateable()) { T entity1 = createEntity(null); if (entity1 != null) { T entity2 = createEntity(null); dao.insert(entity1); dao.insert(entity2); Long pk1 = daoAccess.getKey(entity1); assertNotNull(pk1); Long pk2 = daoAccess.getKey(entity2); assertNotNull(pk2); assertFalse(pk1.equals(pk2)); assertNotNull(dao.load(pk1)); assertNotNull(dao.load(pk2)); } else { DaoLog.d("Skipping testAssignPk for " + daoClass + " (createEntity returned null for null key)"); } } else { DaoLog.d("Skipping testAssignPk for not updateable " + daoClass); } }
/** * We could put the statements inside ThreadLocals (fast enough), but it comes with initialization penalty for new * threads and costs more memory. */ public void _testThreadLocalSpeed() { final Database db = dao.getDatabase(); ThreadLocal<DatabaseStatement> threadLocal = new ThreadLocal<DatabaseStatement>() { @Override protected DatabaseStatement initialValue() { return db.compileStatement("SELECT 42"); } }; threadLocal.get(); long start = SystemClock.currentThreadTimeMillis(); for (int i = 0; i < 1000; i++) { DatabaseStatement sqLiteStatement = threadLocal.get(); assertNotNull(sqLiteStatement); } Long time = SystemClock.currentThreadTimeMillis() - start; DaoLog.d("TIME: " + time + "ms"); // Around 1ms on a S3 assertTrue(time < 10); }
public void testOneByOneUnsubscribe() { insertEntities(1000); RxQuery<TestEntity> bigQuery = daoSession.getTestEntityDao().queryBuilder().rx(); TestSubscriber<TestEntity> testSubscriber = new TestSubscriber<>(); Observable<TestEntity> observable = bigQuery.oneByOne(); Subscription subscription = observable.subscribe(testSubscriber); subscription.unsubscribe(); testSubscriber.assertUnsubscribed(); int count = testSubscriber.getValueCount(); testSubscriber.awaitTerminalEvent(100, TimeUnit.MILLISECONDS); int count2 = testSubscriber.getValueCount(); DaoLog.d("Count 1: " + count + " vs. count 2: " + count2); // Not strictly multi-threading correct, but anyway: assertTrue(count2 < 1000); }
private void runLongSparseArrayTest(long[] keys) { if (keys.length > 10000) { DaoLog.d("Skipping runLongSparseArrayTest for " + keys.length); return; } LongSparseArray<Object> array = new LongSparseArray<Object>(keys.length); startClock("put-sparsearray-" + keys.length); for (long key : keys) { array.put(key, this); } stopClock(); startClock("get-sparsearray-" + keys.length); for (long key : keys) { Object object = array.get(key); if (object != this) { fail("Ups: " + object); } } stopClock(); }