[Benchmarking] Call blackhole#consume() on collections instead of iterating through each element (#7002)

* Replaced iteration with blackhole#consume(the collection)

* Added javadoc on Sequence#toList()
This commit is contained in:
Justin Borromeo 2019-02-20 08:48:06 -08:00 committed by Gian Merlino
parent 554b0142c3
commit 871b9d2f4c
8 changed files with 24 additions and 75 deletions

View File

@ -563,10 +563,7 @@ public class GroupByBenchmark
);
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
for (Row result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -581,10 +578,7 @@ public class GroupByBenchmark
);
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
for (Row result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -602,10 +596,7 @@ public class GroupByBenchmark
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
List<Row> results = queryResult.toList();
for (Row result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -626,10 +617,7 @@ public class GroupByBenchmark
);
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(spillingQuery), new HashMap<>());
List<Row> results = queryResult.toList();
for (Row result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -653,10 +641,7 @@ public class GroupByBenchmark
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
List<Row> results = queryResult.toList();
for (Row result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
private List<QueryRunner<Row>> makeMultiRunners()

View File

@ -418,10 +418,7 @@ public class SearchBenchmark
);
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
List<SearchHit> hits = results.get(0).getValue().getValue();
for (SearchHit hit : hits) {
blackhole.consume(hit);
}
blackhole.consume(results);
}
@Benchmark
@ -436,10 +433,7 @@ public class SearchBenchmark
);
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
List<SearchHit> hits = results.get(0).getValue().getValue();
for (SearchHit hit : hits) {
blackhole.consume(hit);
}
blackhole.consume(results);
}
@ -472,12 +466,6 @@ public class SearchBenchmark
new HashMap<>()
);
List<Result<SearchResultValue>> results = queryResult.toList();
for (Result<SearchResultValue> result : results) {
List<SearchHit> hits = result.getValue().getValue();
for (SearchHit hit : hits) {
blackhole.consume(hit);
}
}
blackhole.consume(results);
}
}

View File

@ -336,9 +336,7 @@ public class SelectBenchmark
if (result.getEvents().size() == 0) {
done = true;
} else {
for (EventHolder eh : result.getEvents()) {
blackhole.consume(eh);
}
blackhole.consume(result);
queryCopy = incrementQueryPagination(queryCopy, result);
}
}
@ -382,9 +380,7 @@ public class SelectBenchmark
if (result.getEvents().size() == 0) {
done = true;
} else {
for (EventHolder eh : result.getEvents()) {
blackhole.consume(eh);
}
blackhole.consume(result);
queryCopy = incrementQueryPagination(queryCopy, result);
}
}

View File

@ -173,10 +173,7 @@ public class SqlBenchmark
{
final Sequence<Row> resultSequence = QueryPlus.wrap(groupByQuery).run(walker, new HashMap<>());
final List<Row> resultList = resultSequence.toList();
for (Row row : resultList) {
blackhole.consume(row);
}
blackhole.consume(resultList);
}
@Benchmark

View File

@ -342,9 +342,7 @@ public class TimeseriesBenchmark
);
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
for (Result<TimeseriesResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -359,9 +357,7 @@ public class TimeseriesBenchmark
);
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
for (Result<TimeseriesResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -379,9 +375,7 @@ public class TimeseriesBenchmark
Query filteredQuery = query.withDimFilter(filter);
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, filteredQuery);
for (Result<TimeseriesResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -414,8 +408,6 @@ public class TimeseriesBenchmark
);
List<Result<TimeseriesResultValue>> results = queryResult.toList();
for (Result<TimeseriesResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
}

View File

@ -326,9 +326,7 @@ public class TopNBenchmark
);
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
for (Result<TopNResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -343,9 +341,7 @@ public class TopNBenchmark
);
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
for (Result<TopNResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@Benchmark
@ -377,9 +373,6 @@ public class TopNBenchmark
new HashMap<>()
);
List<Result<TopNResultValue>> results = queryResult.toList();
for (Result<TopNResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
}

View File

@ -422,10 +422,7 @@ public class TimeCompareBenchmark
{
Sequence<Result<TopNResultValue>> queryResult = topNRunner.run(QueryPlus.wrap(topNQuery), new HashMap<>());
List<Result<TopNResultValue>> results = queryResult.toList();
for (Result<TopNResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
@ -439,9 +436,6 @@ public class TimeCompareBenchmark
new HashMap<>()
);
List<Result<TimeseriesResultValue>> results = queryResult.toList();
for (Result<TimeseriesResultValue> result : results) {
blackhole.consume(result);
}
blackhole.consume(results);
}
}

View File

@ -71,6 +71,10 @@ public interface Sequence<T>
return new MappedSequence<>(this, mapper);
}
/**
* Several benchmarks rely on this method to eagerly accumulate Sequences to ArrayLists. e.g.
* GroupByBenchmark.
*/
default List<T> toList()
{
return accumulate(new ArrayList<>(), Accumulators.list());