10 changed files with 278 additions and 67 deletions
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2019-2022 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.sqlgeneration; |
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode; |
||||||
|
import org.openjdk.jmh.annotations.Fork; |
||||||
|
import org.openjdk.jmh.annotations.Measurement; |
||||||
|
import org.openjdk.jmh.annotations.Mode; |
||||||
|
import org.openjdk.jmh.annotations.OutputTimeUnit; |
||||||
|
import org.openjdk.jmh.annotations.Warmup; |
||||||
|
|
||||||
|
/** |
||||||
|
* Global benchmark settings. |
||||||
|
* |
||||||
|
* @author Mark Paluch |
||||||
|
*/ |
||||||
|
@Warmup(iterations = 5, time = 2000, timeUnit = TimeUnit.MILLISECONDS) |
||||||
|
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS) |
||||||
|
@Fork(value = 1, warmups = 0) |
||||||
|
@BenchmarkMode(Mode.Throughput) |
||||||
|
@OutputTimeUnit(TimeUnit.SECONDS) |
||||||
|
public abstract class BenchmarkSettings { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* 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.sqlgeneration; |
||||||
|
|
||||||
|
import jmh.mbr.junit5.Microbenchmark; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
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.core.dialect.PostgresDialect; |
||||||
|
import org.springframework.data.relational.core.mapping.RelationalMappingContext; |
||||||
|
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; |
||||||
|
|
||||||
|
/** |
||||||
|
* Benchmark for {@link SingleQuerySqlGenerator}. |
||||||
|
* |
||||||
|
* @author Mark Paluch |
||||||
|
*/ |
||||||
|
@Microbenchmark |
||||||
|
public class SingleQuerySqlGeneratorBenchmark extends BenchmarkSettings { |
||||||
|
|
||||||
|
@Benchmark |
||||||
|
public String findAll(StateHolder state) { |
||||||
|
return new SingleQuerySqlGenerator(state.context, state.aliasFactory, PostgresDialect.INSTANCE, |
||||||
|
state.persistentEntity).findAll(null); |
||||||
|
} |
||||||
|
|
||||||
|
@State(Scope.Benchmark) |
||||||
|
public static class StateHolder { |
||||||
|
|
||||||
|
RelationalMappingContext context = new RelationalMappingContext(); |
||||||
|
|
||||||
|
RelationalPersistentEntity<?> persistentEntity; |
||||||
|
|
||||||
|
AliasFactory aliasFactory = new AliasFactory(); |
||||||
|
|
||||||
|
@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) { |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue