Skip to content

Commit 40485dd

Browse files
committed
Introduce AggregatePath benchmark.
See #1679
1 parent 7d59397 commit 40485dd

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.data.relational.core.sqlgeneration;
17+
package org.springframework.data.relational;
1818

1919
import java.util.concurrent.TimeUnit;
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.relational.core.mapping;
17+
18+
import java.util.List;
19+
20+
import org.junit.platform.commons.annotation.Testable;
21+
import org.openjdk.jmh.annotations.Benchmark;
22+
import org.openjdk.jmh.annotations.Scope;
23+
import org.openjdk.jmh.annotations.Setup;
24+
import org.openjdk.jmh.annotations.State;
25+
import org.springframework.data.annotation.Id;
26+
import org.springframework.data.relational.BenchmarkSettings;
27+
28+
/**
29+
* @author Mark Paluch
30+
*/
31+
@Testable
32+
public class AggregatePathBenchmark extends BenchmarkSettings {
33+
34+
@Benchmark
35+
public Object measureAggregatePathAppend(StateHolder holder) {
36+
37+
holder.context.getAggregatePath(holder.persistentEntity)
38+
.append(holder.persistentEntity.getRequiredPersistentProperty("id"));
39+
holder.context.getAggregatePath(holder.persistentEntity)
40+
.append(holder.persistentEntity.getRequiredPersistentProperty("name"));
41+
return holder.context.getAggregatePath(holder.persistentEntity)
42+
.append(holder.persistentEntity.getRequiredPersistentProperty("trivials"));
43+
}
44+
45+
@Benchmark
46+
public Object measureGetAggregatePathAppend(StateHolder holder) {
47+
48+
return holder.context.getAggregatePath(holder.persistentEntity)
49+
.append(holder.persistentEntity.getRequiredPersistentProperty("id"));
50+
}
51+
52+
@State(Scope.Benchmark)
53+
public static class StateHolder {
54+
55+
RelationalMappingContext context = new RelationalMappingContext();
56+
57+
RelationalPersistentEntity<?> persistentEntity;
58+
59+
@Setup
60+
public void setup() {
61+
persistentEntity = context.getRequiredPersistentEntity(SingleReferenceAggregate.class);
62+
}
63+
}
64+
65+
record TrivialAggregate(@Id Long id, String name) {
66+
}
67+
68+
record SingleReferenceAggregate(@Id Long id, String name, List<TrivialAggregate> trivials) {
69+
}
70+
}

spring-data-relational/src/jmh/java/org/springframework/data/relational/core/sqlgeneration/SingleQuerySqlGeneratorBenchmark.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openjdk.jmh.annotations.Setup;
2525
import org.openjdk.jmh.annotations.State;
2626
import org.springframework.data.annotation.Id;
27+
import org.springframework.data.relational.BenchmarkSettings;
2728
import org.springframework.data.relational.core.dialect.PostgresDialect;
2829
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
2930
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;

0 commit comments

Comments
 (0)