Introduce AggregatePath benchmark.

See #1679
This commit is contained in:
Mark Paluch
2023-11-29 09:48:15 +01:00
parent ee01650a7f
commit 060bc2f30b
3 changed files with 73 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.relational.core.sqlgeneration;
package org.springframework.data.relational;
import java.util.concurrent.TimeUnit;

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.mapping;
import java.util.List;
import org.junit.platform.commons.annotation.Testable;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.BenchmarkSettings;
/**
* @author Mark Paluch
*/
@Testable
public class AggregatePathBenchmark extends BenchmarkSettings {
@Benchmark
public Object measureAggregatePathAppend(StateHolder holder) {
holder.context.getAggregatePath(holder.persistentEntity)
.append(holder.persistentEntity.getRequiredPersistentProperty("id"));
holder.context.getAggregatePath(holder.persistentEntity)
.append(holder.persistentEntity.getRequiredPersistentProperty("name"));
return holder.context.getAggregatePath(holder.persistentEntity)
.append(holder.persistentEntity.getRequiredPersistentProperty("trivials"));
}
@Benchmark
public Object measureGetAggregatePathAppend(StateHolder holder) {
return holder.context.getAggregatePath(holder.persistentEntity)
.append(holder.persistentEntity.getRequiredPersistentProperty("id"));
}
@State(Scope.Benchmark)
public static class StateHolder {
RelationalMappingContext context = new RelationalMappingContext();
RelationalPersistentEntity<?> persistentEntity;
@Setup
public void setup() {
persistentEntity = context.getRequiredPersistentEntity(SingleReferenceAggregate.class);
}
}
record TrivialAggregate(@Id Long id, String name) {
}
record SingleReferenceAggregate(@Id Long id, String name, List<TrivialAggregate> trivials) {
}
}

View File

@@ -24,6 +24,7 @@ import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.BenchmarkSettings;
import org.springframework.data.relational.core.dialect.PostgresDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;