Skip to content

Commit bf67b62

Browse files
Add runs to Active Android indexed test.
1 parent 2f043f4 commit bf67b62

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

PerformanceTests/ActiveAndroid/src/androidTest/java/de/greenrobot/performance/activeandroid/PerformanceTestActiveAndroid.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class PerformanceTestActiveAndroid extends ApplicationTestCase<Applicatio
2020
private static final String TAG = "PerfTestActiveAndroid";
2121

2222
private static final int BATCH_SIZE = 10000;
23+
private static final int QUERY_COUNT = 1000;
2324
private static final int RUNS = 8;
24-
private static final int INDEXED_RUNS = 1000;
2525

2626
private static final String DATABASE_NAME = "active-android.db";
2727

@@ -52,9 +52,17 @@ public void testIndexedStringEntityQuery() {
5252
Log.d(TAG, "Performance tests are disabled.");
5353
return;
5454
}
55+
Log.d(TAG, "--------Indexed Queries: Start");
5556

56-
Log.d(TAG, "---------------Indexed Queries: Start");
57+
for (int i = 0; i < RUNS; i++) {
58+
Log.d(TAG, "----Run " + (i + 1) + " of " + RUNS);
59+
doIndexedStringEntityQuery();
60+
}
61+
62+
Log.d(TAG, "--------Indexed Queries: End");
63+
}
5764

65+
private void doIndexedStringEntityQuery() {
5866
// set up database
5967
Configuration dbConfiguration = new Configuration.Builder(getContext())
6068
.setDatabaseName(DATABASE_NAME)
@@ -86,21 +94,26 @@ public void testIndexedStringEntityQuery() {
8694
Log.d(TAG, "Inserted entities.");
8795

8896
// query for entities by indexed string at random
89-
int[] randomIndices = StringGenerator.getFixedRandomIndices(INDEXED_RUNS, BATCH_SIZE - 1);
97+
int[] randomIndices = StringGenerator.getFixedRandomIndices(QUERY_COUNT, BATCH_SIZE - 1);
9098

9199
long start = System.currentTimeMillis();
92-
for (int i = 0; i < INDEXED_RUNS; i++) {
100+
for (int i = 0; i < QUERY_COUNT; i++) {
93101
int nextIndex = randomIndices[i];
102+
//noinspection unused
94103
List<IndexedStringEntity> query = new Select()
95104
.from(IndexedStringEntity.class)
96105
.where("INDEXED_STRING = ?", fixedRandomStrings[nextIndex])
97106
.execute();
98107
// ActiveAndroid already builds all entities when executing the query, so move on
99108
}
100109
long time = System.currentTimeMillis() - start;
101-
Log.d(TAG, "Queried for " + INDEXED_RUNS + " indexed entities in " + time + " ms");
110+
Log.d(TAG,
111+
"Queried for " + QUERY_COUNT + " of " + BATCH_SIZE + " indexed entities in " + time
112+
+ " ms.");
102113

103-
Log.d(TAG, "---------------Indexed Queries: End");
114+
// delete all entities
115+
ActiveAndroid.execSQL("DELETE FROM INDEXED_STRING_ENTITY");
116+
Log.d(TAG, "Deleted all entities.");
104117
}
105118

106119
public void testPerformance() throws Exception {

0 commit comments

Comments
 (0)