mirror of https://github.com/apache/druid.git
[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:
parent
554b0142c3
commit
871b9d2f4c
|
@ -563,10 +563,7 @@ public class GroupByBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
|
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
|
||||||
|
blackhole.consume(results);
|
||||||
for (Row result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -581,10 +578,7 @@ public class GroupByBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
|
List<Row> results = GroupByBenchmark.runQuery(factory, runner, query);
|
||||||
|
blackhole.consume(results);
|
||||||
for (Row result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -602,10 +596,7 @@ public class GroupByBenchmark
|
||||||
|
|
||||||
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
|
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
|
||||||
List<Row> results = queryResult.toList();
|
List<Row> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Row result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -626,10 +617,7 @@ public class GroupByBenchmark
|
||||||
);
|
);
|
||||||
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(spillingQuery), new HashMap<>());
|
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(spillingQuery), new HashMap<>());
|
||||||
List<Row> results = queryResult.toList();
|
List<Row> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Row result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -653,10 +641,7 @@ public class GroupByBenchmark
|
||||||
|
|
||||||
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
|
Sequence<Row> queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>());
|
||||||
List<Row> results = queryResult.toList();
|
List<Row> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Row result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<QueryRunner<Row>> makeMultiRunners()
|
private List<QueryRunner<Row>> makeMultiRunners()
|
||||||
|
|
|
@ -418,10 +418,7 @@ public class SearchBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
|
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
|
||||||
List<SearchHit> hits = results.get(0).getValue().getValue();
|
blackhole.consume(results);
|
||||||
for (SearchHit hit : hits) {
|
|
||||||
blackhole.consume(hit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -436,10 +433,7 @@ public class SearchBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
|
List<Result<SearchResultValue>> results = SearchBenchmark.runQuery(factory, runner, query);
|
||||||
List<SearchHit> hits = results.get(0).getValue().getValue();
|
blackhole.consume(results);
|
||||||
for (SearchHit hit : hits) {
|
|
||||||
blackhole.consume(hit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -472,12 +466,6 @@ public class SearchBenchmark
|
||||||
new HashMap<>()
|
new HashMap<>()
|
||||||
);
|
);
|
||||||
List<Result<SearchResultValue>> results = queryResult.toList();
|
List<Result<SearchResultValue>> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Result<SearchResultValue> result : results) {
|
|
||||||
List<SearchHit> hits = result.getValue().getValue();
|
|
||||||
for (SearchHit hit : hits) {
|
|
||||||
blackhole.consume(hit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,9 +336,7 @@ public class SelectBenchmark
|
||||||
if (result.getEvents().size() == 0) {
|
if (result.getEvents().size() == 0) {
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
for (EventHolder eh : result.getEvents()) {
|
blackhole.consume(result);
|
||||||
blackhole.consume(eh);
|
|
||||||
}
|
|
||||||
queryCopy = incrementQueryPagination(queryCopy, result);
|
queryCopy = incrementQueryPagination(queryCopy, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,9 +380,7 @@ public class SelectBenchmark
|
||||||
if (result.getEvents().size() == 0) {
|
if (result.getEvents().size() == 0) {
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
for (EventHolder eh : result.getEvents()) {
|
blackhole.consume(result);
|
||||||
blackhole.consume(eh);
|
|
||||||
}
|
|
||||||
queryCopy = incrementQueryPagination(queryCopy, result);
|
queryCopy = incrementQueryPagination(queryCopy, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,10 +173,7 @@ public class SqlBenchmark
|
||||||
{
|
{
|
||||||
final Sequence<Row> resultSequence = QueryPlus.wrap(groupByQuery).run(walker, new HashMap<>());
|
final Sequence<Row> resultSequence = QueryPlus.wrap(groupByQuery).run(walker, new HashMap<>());
|
||||||
final List<Row> resultList = resultSequence.toList();
|
final List<Row> resultList = resultSequence.toList();
|
||||||
|
blackhole.consume(resultList);
|
||||||
for (Row row : resultList) {
|
|
||||||
blackhole.consume(row);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
|
|
@ -342,9 +342,7 @@ public class TimeseriesBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
|
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
|
||||||
for (Result<TimeseriesResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -359,9 +357,7 @@ public class TimeseriesBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
|
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, query);
|
||||||
for (Result<TimeseriesResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -379,9 +375,7 @@ public class TimeseriesBenchmark
|
||||||
Query filteredQuery = query.withDimFilter(filter);
|
Query filteredQuery = query.withDimFilter(filter);
|
||||||
|
|
||||||
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, filteredQuery);
|
List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, filteredQuery);
|
||||||
for (Result<TimeseriesResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -414,8 +408,6 @@ public class TimeseriesBenchmark
|
||||||
);
|
);
|
||||||
List<Result<TimeseriesResultValue>> results = queryResult.toList();
|
List<Result<TimeseriesResultValue>> results = queryResult.toList();
|
||||||
|
|
||||||
for (Result<TimeseriesResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,9 +326,7 @@ public class TopNBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
|
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
|
||||||
for (Result<TopNResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -343,9 +341,7 @@ public class TopNBenchmark
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
|
List<Result<TopNResultValue>> results = TopNBenchmark.runQuery(factory, runner, query);
|
||||||
for (Result<TopNResultValue> result : results) {
|
blackhole.consume(results);
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
@ -377,9 +373,6 @@ public class TopNBenchmark
|
||||||
new HashMap<>()
|
new HashMap<>()
|
||||||
);
|
);
|
||||||
List<Result<TopNResultValue>> results = queryResult.toList();
|
List<Result<TopNResultValue>> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Result<TopNResultValue> result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,10 +422,7 @@ public class TimeCompareBenchmark
|
||||||
{
|
{
|
||||||
Sequence<Result<TopNResultValue>> queryResult = topNRunner.run(QueryPlus.wrap(topNQuery), new HashMap<>());
|
Sequence<Result<TopNResultValue>> queryResult = topNRunner.run(QueryPlus.wrap(topNQuery), new HashMap<>());
|
||||||
List<Result<TopNResultValue>> results = queryResult.toList();
|
List<Result<TopNResultValue>> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Result<TopNResultValue> result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -439,9 +436,6 @@ public class TimeCompareBenchmark
|
||||||
new HashMap<>()
|
new HashMap<>()
|
||||||
);
|
);
|
||||||
List<Result<TimeseriesResultValue>> results = queryResult.toList();
|
List<Result<TimeseriesResultValue>> results = queryResult.toList();
|
||||||
|
blackhole.consume(results);
|
||||||
for (Result<TimeseriesResultValue> result : results) {
|
|
||||||
blackhole.consume(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,10 @@ public interface Sequence<T>
|
||||||
return new MappedSequence<>(this, mapper);
|
return new MappedSequence<>(this, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Several benchmarks rely on this method to eagerly accumulate Sequences to ArrayLists. e.g.
|
||||||
|
* GroupByBenchmark.
|
||||||
|
*/
|
||||||
default List<T> toList()
|
default List<T> toList()
|
||||||
{
|
{
|
||||||
return accumulate(new ArrayList<>(), Accumulators.list());
|
return accumulate(new ArrayList<>(), Accumulators.list());
|
||||||
|
|
Loading…
Reference in New Issue