Skip to content

Commit 29acd8e

Browse files
Add indexed string test for Parse.
- Add dependency on Common module. - Update parse-android to 1.10.2 (no changelog to be found :(.
1 parent 1975313 commit 29acd8e

File tree

3 files changed

+103
-11
lines changed

3 files changed

+103
-11
lines changed

PerformanceTests/Parse/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ android {
2929
}
3030

3131
dependencies {
32+
androidTestCompile project(':PerformanceTests:Common')
3233
compile 'com.parse.bolts:bolts-android:1.2.1'
33-
compile 'com.parse:parse-android:1.10.1'
34+
compile 'com.parse:parse-android:1.10.2'
3435
}
3536

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package de.greenrobot.performance.parse;
2+
3+
import com.parse.ParseClassName;
4+
import com.parse.ParseObject;
5+
6+
/**
7+
* Simple entity with a string property.
8+
*/
9+
@ParseClassName("IndexedStringEntity")
10+
public class IndexedStringEntity extends ParseObject {
11+
12+
// Parse does not seem to support manual definition of indexes, so NOT actually indexed
13+
public static final String INDEXED_STRING = "indexedString";
14+
15+
public String getIndexedString() {
16+
return getString(INDEXED_STRING);
17+
}
18+
19+
public void setIndexedString(String value) {
20+
put(INDEXED_STRING, value);
21+
}
22+
23+
}

PerformanceTests/Parse/src/androidTest/java/de/greenrobot/performance/parse/PerformanceTestParse.java

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.parse.ParseObject;
1010
import com.parse.ParseQuery;
1111
import com.parse.ParseUser;
12+
import de.greenrobot.performance.StringGenerator;
1213
import java.util.ArrayList;
1314
import java.util.List;
1415

@@ -19,7 +20,10 @@ public class PerformanceTestParse extends ApplicationTestCase<Application> {
1920

2021
private static final String TAG = "PerfTestParse";
2122

22-
private static final int BATCH_SIZE = 10000;
23+
// reduced batch size due to memory leak when pinning (of bolts.Task?)
24+
private static final int BATCH_SIZE = 1000;
25+
// reduced query count due to slow performance
26+
private static final int QUERY_COUNT = 100;
2327
private static final int RUNS = 8;
2428

2529
public PerformanceTestParse() {
@@ -55,30 +59,87 @@ private void setupParse() {
5559
ParseACL.setDefaultACL(defaultACL, true);
5660
}
5761

58-
public void testPerformance() throws Exception {
62+
public void testIndexedStringEntityQuery() throws ParseException {
63+
// According to the documentation, Parse does NOT support defining indexes manually
64+
// or for the local datastore.
65+
// We still are going to determine query performance WITHOUT AN INDEX.
66+
67+
//noinspection PointlessBooleanExpression
68+
if (!BuildConfig.RUN_PERFORMANCE_TESTS) {
69+
Log.d(TAG, "Performance tests are disabled.");
70+
return;
71+
}
72+
Log.d(TAG, "--------Indexed Queries: Start");
73+
5974
// set up parse inside of test
6075
// setting it up in setUp() breaks Parse, as it keeps its init state between tests
6176
// in hidden ParsePlugins
77+
ParseObject.registerSubclass(IndexedStringEntity.class);
6278
setupParse();
6379

80+
for (int i = 0; i < RUNS; i++) {
81+
Log.d(TAG, "----Run " + (i + 1) + " of " + RUNS);
82+
doIndexedStringEntityQuery();
83+
}
84+
85+
Log.d(TAG, "--------Indexed Queries: End");
86+
}
87+
88+
private void doIndexedStringEntityQuery() throws ParseException {
89+
// create entities
90+
List<IndexedStringEntity> entities = new ArrayList<>(BATCH_SIZE);
91+
String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(BATCH_SIZE);
92+
for (int i = 0; i < BATCH_SIZE; i++) {
93+
IndexedStringEntity entity = new IndexedStringEntity();
94+
entity.setIndexedString(fixedRandomStrings[i]);
95+
entities.add(entity);
96+
}
97+
Log.d(TAG, "Built entities.");
98+
99+
// insert entities
100+
ParseObject.pinAll(entities);
101+
Log.d(TAG, "Inserted entities.");
102+
103+
// query for entities by indexed string at random
104+
int[] randomIndices = StringGenerator.getFixedRandomIndices(QUERY_COUNT, BATCH_SIZE - 1);
105+
106+
long start = System.currentTimeMillis();
107+
for (int i = 0; i < QUERY_COUNT; i++) {
108+
int nextIndex = randomIndices[i];
109+
110+
ParseQuery<IndexedStringEntity> query = ParseQuery.getQuery(IndexedStringEntity.class);
111+
query.whereEqualTo(IndexedStringEntity.INDEXED_STRING, fixedRandomStrings[nextIndex]);
112+
//noinspection unused
113+
List<IndexedStringEntity> result = query.find();
114+
}
115+
long time = System.currentTimeMillis() - start;
116+
Log.d(TAG,
117+
"Queried for " + QUERY_COUNT + " of " + BATCH_SIZE + " UNINDEXED entities in "
118+
+ time + " ms.");
119+
120+
// delete all entities
121+
ParseObject.unpinAll();
122+
Log.d(TAG, "Deleted all entities.");
123+
}
124+
125+
public void testPerformance() throws Exception {
64126
//noinspection PointlessBooleanExpression
65127
if (!BuildConfig.RUN_PERFORMANCE_TESTS) {
66128
Log.d(TAG, "Performance tests are disabled.");
67129
return;
68130
}
69-
70131
Log.d(TAG, "---------------Start");
132+
133+
// set up parse inside of test
134+
// setting it up in setUp() breaks Parse, as it keeps its init state between tests
135+
// in hidden ParsePlugins
136+
setupParse();
137+
71138
for (int i = 0; i < RUNS; i++) {
72139
runTests(BATCH_SIZE);
73140
}
74-
Log.d(TAG, "---------------End");
75-
}
76141

77-
private void deleteAll() throws ParseException {
78-
long start = System.currentTimeMillis();
79-
ParseObject.unpinAll();
80-
long time = System.currentTimeMillis() - start;
81-
Log.d(TAG, "Deleted all entities in " + time + " ms");
142+
Log.d(TAG, "---------------End");
82143
}
83144

84145
private void runTests(int entityCount) throws ParseException {
@@ -154,6 +215,13 @@ private void runOneByOne(List<ParseObject> list, int count) throws ParseExceptio
154215
Log.d(TAG, "Updated (one-by-one) " + count + " entities in " + time + " ms");
155216
}
156217

218+
private void deleteAll() throws ParseException {
219+
long start = System.currentTimeMillis();
220+
ParseObject.unpinAll();
221+
long time = System.currentTimeMillis() - start;
222+
Log.d(TAG, "Deleted all entities in " + time + " ms");
223+
}
224+
157225
private ParseObject createEntity(int nr) {
158226
ParseObject entity = new ParseObject("SimpleEntity");
159227
entity.put("simpleBoolean", true);

0 commit comments

Comments
 (0)