Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public void run(TestType type) {
case TestType.QUERY_STRING_INDEXED:
runQueryByStringIndexed();
break;
case TestType.QUERY_INTEGER:
runQueryByInteger();
break;
case TestType.QUERY_INTEGER_INDEXED:
runQueryByIntegerIndexed();
break;
case TestType.QUERY_ID:
runQueryById(false);
break;
Expand Down Expand Up @@ -303,6 +309,71 @@ private void runQueryByStringIndexed() {
log("Entities found: " + entitiesFound);
}


private void runQueryByIntegerIndexed() {
if (numberEntities > 10000) {
log("Reduce number of entities to 10000 to avoid extremely long test runs");
return;
}
List<SimpleEntityIndexed> entities = new ArrayList<>(numberEntities);
for (int i = 0; i < numberEntities; i++) {
entities.add(createEntityIndexed(i));
}

startBenchmark("insert");
realm.beginTransaction();
realm.insert(entities);
realm.commitTransaction();
stopBenchmark();

final int[] valuesToLookup = new int[numberEntities];
for (int i = 0; i < numberEntities; i++) {
valuesToLookup[i] = entities.get(random.nextInt(numberEntities)).getSimpleInt();
}

startBenchmark("query");
long entitiesFound = 0;
for (int i = 0; i < numberEntities; i++) {
List<SimpleEntityIndexed> result = realm.where(SimpleEntityIndexed.class).equalTo("simpleInt", valuesToLookup[i]).findAll();
accessAllIndexed(result);
entitiesFound += result.size();
}
stopBenchmark();
log("Entities found: " + entitiesFound);
}

private void runQueryByInteger() {
if (numberEntities > 10000) {
log("Reduce number of entities to 10000 to avoid extremely long test runs");
return;
}
List<SimpleEntity> entities = new ArrayList<>(numberEntities);
for (int i = 0; i < numberEntities; i++) {
entities.add(createEntity(i, false));
}

startBenchmark("insert");
realm.beginTransaction();
realm.insert(entities);
realm.commitTransaction();
stopBenchmark();

final int[] valuesToLookup = new int[numberEntities];
for (int i = 0; i < numberEntities; i++) {
valuesToLookup[i] = entities.get(random.nextInt(numberEntities)).getSimpleInt();
}

startBenchmark("query");
long entitiesFound = 0;
for (int i = 0; i < numberEntities; i++) {
List<SimpleEntity> result = realm.where(SimpleEntity.class).equalTo("simpleInt", valuesToLookup[i]).findAll();
accessAll(result);
entitiesFound += result.size();
}
stopBenchmark();
log("Entities found: " + entitiesFound);
}

private void runQueryById(boolean randomIds) {
List<SimpleEntity> entities = new ArrayList<>(numberEntities);
for (int i = 0; i < numberEntities; i++) {
Expand Down