9
9
import com .parse .ParseObject ;
10
10
import com .parse .ParseQuery ;
11
11
import com .parse .ParseUser ;
12
+ import de .greenrobot .performance .StringGenerator ;
12
13
import java .util .ArrayList ;
13
14
import java .util .List ;
14
15
@@ -19,7 +20,10 @@ public class PerformanceTestParse extends ApplicationTestCase<Application> {
19
20
20
21
private static final String TAG = "PerfTestParse" ;
21
22
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 ;
23
27
private static final int RUNS = 8 ;
24
28
25
29
public PerformanceTestParse () {
@@ -55,30 +59,87 @@ private void setupParse() {
55
59
ParseACL .setDefaultACL (defaultACL , true );
56
60
}
57
61
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
+
59
74
// set up parse inside of test
60
75
// setting it up in setUp() breaks Parse, as it keeps its init state between tests
61
76
// in hidden ParsePlugins
77
+ ParseObject .registerSubclass (IndexedStringEntity .class );
62
78
setupParse ();
63
79
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 {
64
126
//noinspection PointlessBooleanExpression
65
127
if (!BuildConfig .RUN_PERFORMANCE_TESTS ) {
66
128
Log .d (TAG , "Performance tests are disabled." );
67
129
return ;
68
130
}
69
-
70
131
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
+
71
138
for (int i = 0 ; i < RUNS ; i ++) {
72
139
runTests (BATCH_SIZE );
73
140
}
74
- Log .d (TAG , "---------------End" );
75
- }
76
141
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" );
82
143
}
83
144
84
145
private void runTests (int entityCount ) throws ParseException {
@@ -154,6 +215,13 @@ private void runOneByOne(List<ParseObject> list, int count) throws ParseExceptio
154
215
Log .d (TAG , "Updated (one-by-one) " + count + " entities in " + time + " ms" );
155
216
}
156
217
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
+
157
225
private ParseObject createEntity (int nr ) {
158
226
ParseObject entity = new ParseObject ("SimpleEntity" );
159
227
entity .put ("simpleBoolean" , true );
0 commit comments