diff --git a/benchmark/commons/pom.xml b/benchmark/commons/pom.xml index 350324e..d50d481 100644 --- a/benchmark/commons/pom.xml +++ b/benchmark/commons/pom.xml @@ -5,7 +5,7 @@ 4.0.0 - org.springframework.data + org.springframework.data.benchmark spring-data-benchmark-parent 2.2.0.BUILD-SNAPSHOT @@ -22,7 +22,7 @@ - ${project.groupId} + org.springframework.data spring-data-commons diff --git a/benchmark/mongodb/pom.xml b/benchmark/mongodb/pom.xml index 31cbc6d..ba4e7df 100644 --- a/benchmark/mongodb/pom.xml +++ b/benchmark/mongodb/pom.xml @@ -5,7 +5,7 @@ 4.0.0 - org.springframework.data + org.springframework.data.benchmark spring-data-benchmark-parent 2.2.0.BUILD-SNAPSHOT @@ -22,21 +22,13 @@ - ${project.groupId} + org.springframework.data spring-data-commons - 2.2.0.BUILD-SNAPSHOT - ${project.groupId} + org.springframework.data spring-data-mongodb - 2.2.0.BUILD-SNAPSHOT - - - - org.mockito - mockito-core - 2.28.2 diff --git a/benchmark/pom.xml b/benchmark/pom.xml index 2a3063b..5b6ed38 100644 --- a/benchmark/pom.xml +++ b/benchmark/pom.xml @@ -1,10 +1,11 @@ - + 4.0.0 - org.springframework.data + org.springframework.data.benchmark spring-data-benchmark-parent pom @@ -21,18 +22,20 @@ support commons mongodb + relational Moore-BUILD-SNAPSHOT 1.19 + 2.2.0.BUILD-SNAPSHOT - ${project.groupId} + org.springframework.data spring-data-releasetrain ${releasetrain.version} pom @@ -83,6 +86,17 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + true + + pl.project13.maven git-commit-id-plugin diff --git a/benchmark/relational/pom.xml b/benchmark/relational/pom.xml new file mode 100644 index 0000000..5161549 --- /dev/null +++ b/benchmark/relational/pom.xml @@ -0,0 +1,80 @@ + + + + 4.0.0 + + + org.springframework.data.benchmark + spring-data-benchmark-parent + 2.2.0.BUILD-SNAPSHOT + + + spring-data-benchmark-relational + + Spring Data Benchmarks - Relational Microbenchmarks + + + + + ${project.groupId} + spring-data-benchmark-support + + + + org.springframework.data + spring-data-commons + 2.2.0.DATACMNS-1556-SNAPSHOT + + + + org.springframework.data + spring-data-jpa + 2.2.0.DATAJPA-1575-SNAPSHOT + + + + org.springframework.data + spring-data-jdbc + 1.1.0.DATAJDBC-399-SNAPSHOT + + + + org.springframework.data + spring-data-relational + 1.1.0.DATAJDBC-399-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-data-jdbc + ${spring-boot.version} + + + + com.h2database + h2 + 1.4.197 + + + + org.mockito + mockito-core + ${mockito} + + + + com.mockrunner + mockrunner-jdbc + 2.0.1 + + + + + diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/Constants.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/Constants.java new file mode 100644 index 0000000..bce1ae9 --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/Constants.java @@ -0,0 +1,24 @@ +/* + * Copyright 2019 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.microbenchmark; + +/** + * @author Oliver Drotbohm + */ +public class Constants { + + public static final int NUMBER_OF_BOOKS = 8; +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/Book.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/Book.java new file mode 100644 index 0000000..715836f --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/Book.java @@ -0,0 +1,33 @@ +/* + * Copyright 2019 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.microbenchmark.jdbc; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import org.springframework.data.annotation.Id; + +/** + * @author Oliver Drotbohm + */ +@Data +@AllArgsConstructor +public class Book { + + private @Id Long id; + private String title; + private int pages; +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcBenchmark.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcBenchmark.java new file mode 100644 index 0000000..8ccc965 --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcBenchmark.java @@ -0,0 +1,64 @@ +/* + * Copyright 2019 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.microbenchmark.jdbc; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.util.Optional; +import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark; + +/** + * @author Oliver Drotbohm + */ +public class JdbcBenchmark extends AbstractMicrobenchmark { + + private JdbcFixture fixture; + + @Setup + public void setUp() { + this.fixture = new JdbcFixture(); + } + + @TearDown + public void tearDown() { + fixture.close(); + } + + @Benchmark + public void findByTitle(Blackhole sink) { + + Book book = fixture.getOperations().queryForObject("SELECT id, title, pages FROM Book where title = ?1", + new Object[] { "title0" }, fixture.getBookMapper()); + + sink.consume(book); + } + + @Benchmark + public void findByTitleOptional(Blackhole sink) { + + Book book = fixture.getOperations().queryForObject("SELECT id, title, pages FROM Book where title = ?1", + new Object[] { "title0" }, fixture.getBookMapper()); + + sink.consume(Optional.of(book)); + } + + @Benchmark + public void findAll(Blackhole sink) { + sink.consume(fixture.getOperations().query("SELECT id, title, pages FROM Book", fixture.getBookMapper())); + } +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcFixture.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcFixture.java new file mode 100644 index 0000000..fb9097e --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcFixture.java @@ -0,0 +1,74 @@ +/* + * Copyright 2019 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.microbenchmark.jdbc; + +import lombok.Getter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.IntStream; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.data.microbenchmark.Constants; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.RowMapper; + +/** + * @author Oliver Drotbohm + */ +public class JdbcFixture { + + private final @Getter JdbcOperations operations; + private final @Getter RowMapper bookMapper; + private final List books = new ArrayList<>(); + + private final @Getter ConfigurableApplicationContext context; + + public JdbcFixture() { + + SpringApplication application = new SpringApplication(); + application.addPrimarySources(Collections.singletonList(JdbcApplication.class)); + application.setLazyInitialization(true); + application.setAdditionalProfiles("jdbc"); + this.context = application.run(); + + this.operations = context.getBean(JdbcOperations.class); + + // Schema + this.operations.execute( + "create table Book (id bigint not null auto_increment, title varchar(255), pages integer not null, primary key (id))"); + + // Data + IntStream.range(0, Constants.NUMBER_OF_BOOKS) // + .mapToObj(it -> new Book(null, "title" + it, it)) // + .peek(it -> books.add(it)) // + .forEach(it -> operations.update("INSERT INTO Book VALUES (null, ?1, ?2)", it.getTitle(), it.getPages())); + + this.bookMapper = (rs, rowNum) -> new Book(rs.getLong("id"), rs.getString("title"), rs.getInt("pages")); + } + + @SpringBootApplication + static class JdbcApplication { + + } + + public void close() { + context.close(); + } +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/JdbcBookRepository.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/JdbcBookRepository.java new file mode 100644 index 0000000..89b02cf --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/JdbcBookRepository.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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.microbenchmark.jdbc.springdata; + +import java.util.Optional; + +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.microbenchmark.jdbc.Book; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Oliver Drotbohm + */ +public interface JdbcBookRepository extends CrudRepository { + + @Query("SELECT id, title, pages FROM Book where title = :title") + Book findByTitle(String title); + + @Query("SELECT id, title, pages FROM Book where title = :title") + Optional findOptionalByTitle(String title); +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/SpringDataJdbcBenchmark.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/SpringDataJdbcBenchmark.java new file mode 100644 index 0000000..09470ec --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/springdata/SpringDataJdbcBenchmark.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019 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.microbenchmark.jdbc.springdata; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.infra.Blackhole; +import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark; +import org.springframework.data.microbenchmark.jdbc.JdbcFixture; + +/** + * @author Oliver Drotbohm + */ +public class SpringDataJdbcBenchmark extends AbstractMicrobenchmark { + + private JdbcBookRepository repository; + + @Setup + public void setUp() { + + JdbcFixture fixture = new JdbcFixture(); + + this.repository = fixture.getContext().getBean(JdbcBookRepository.class); + } + + @Benchmark + public void findByTitle(Blackhole sink) { + + sink.consume(repository.findByTitle("title0")); + } + + @Benchmark + public void findByTitleOptional(Blackhole sink) { + + sink.consume(repository.findOptionalByTitle("title0")); + } + + @Benchmark + public void findAll(Blackhole sink) { + + sink.consume(repository.findAll()); + } +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/Book.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/Book.java new file mode 100644 index 0000000..3a8035b --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/Book.java @@ -0,0 +1,38 @@ +/* + * Copyright 2019 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.microbenchmark.jpa; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +/** + * @author Oliver Drotbohm + */ +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Book { + + private @GeneratedValue @Id Long id; + private String title; + private int pages; +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaBenchmark.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaBenchmark.java new file mode 100644 index 0000000..70f5abf --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaBenchmark.java @@ -0,0 +1,93 @@ +/* + * Copyright 2019 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.microbenchmark.jpa; + +import java.util.Optional; + +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.ParameterExpression; +import javax.persistence.criteria.Root; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.infra.Blackhole; +import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark; + +/** + * @author Oliver Drotbohm + */ +public class JpaBenchmark extends AbstractMicrobenchmark { + + private JpaFixture fixture; + + @Setup + public void setUp() { + this.fixture = new JpaFixture(); + } + + @Benchmark + public void findByTitle(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + + Query query = em.createQuery("select b from Book b where b.title = ?1"); + query.setParameter(1, "title0"); + + sink.consume(query.getSingleResult()); + }); + } + + @Benchmark + public void findByTitleCriteria(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery q = cb.createQuery(Book.class); + Root c = q.from(Book.class); + + ParameterExpression parameter = cb.parameter(String.class); + + TypedQuery query = em.createQuery(q.select(c).where(cb.equal(c.get("title"), parameter))); + query.setParameter(parameter, "title0"); + + sink.consume(query.getSingleResult()); + }); + } + + @Benchmark + public void findByTitleOptional(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + + Query query = em.createQuery("select b from Book b where b.title = ?1"); + query.setParameter(1, "title0"); + + sink.consume(Optional.of(query.getSingleResult())); + }); + } + + @Benchmark + public void findAll(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + sink.consume(em.createQuery("select b from Book b").getResultList()); + }); + } +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaFixture.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaFixture.java new file mode 100644 index 0000000..0a5f55b --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaFixture.java @@ -0,0 +1,83 @@ +/* + * Copyright 2019 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.microbenchmark.jpa; + +import lombok.Getter; + +import java.util.Collections; +import java.util.function.Consumer; +import java.util.stream.IntStream; + +import javax.persistence.EntityManager; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.data.microbenchmark.Constants; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.DefaultTransactionDefinition; + +/** + * @author Oliver Drotbohm + */ +public class JpaFixture { + + private final @Getter ConfigurableApplicationContext context; + + public JpaFixture() { + + SpringApplication application = new SpringApplication(); + application.addPrimarySources(Collections.singletonList(JpaApplication.class)); + application.setAdditionalProfiles("jpa"); + application.setLazyInitialization(true); + + this.context = application.run(); + + withTransactionalEntityManager(em -> { + + IntStream.range(0, Constants.NUMBER_OF_BOOKS) // + .mapToObj(it -> new Book(null, "title" + it, it)) // + .forEach(em::persist); + }); + } + + public void withTransactionalEntityManager(Consumer consumer) { + + PlatformTransactionManager manager = context.getBean(PlatformTransactionManager.class); + TransactionStatus status = manager.getTransaction(new DefaultTransactionDefinition()); + + EntityManager em = context.getBean(EntityManager.class); + + consumer.accept(em); + + em.flush(); + manager.commit(status); + em.close(); + } + + public void withNonTransactionalEntityManager(Consumer consumer) { + + EntityManager em = context.getBean(EntityManager.class); + + consumer.accept(em); + + em.close(); + } + + @SpringBootApplication + static class JpaApplication {} +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/JpaBookRepository.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/JpaBookRepository.java new file mode 100644 index 0000000..933e735 --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/JpaBookRepository.java @@ -0,0 +1,35 @@ +/* + * Copyright 2019 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.microbenchmark.jpa.springdata; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.microbenchmark.jpa.Book; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Oliver Drotbohm + */ +public interface JpaBookRepository extends CrudRepository { + + @Query("select b from Book b where b.title = :title") + Book findDeclaredByTitle(String title); + + Book findDerivedByTitle(String title); + + Optional findOptionalDerivedByTitle(String title); +} diff --git a/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/SpringDataJpaBenchmark.java b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/SpringDataJpaBenchmark.java new file mode 100644 index 0000000..db80d0d --- /dev/null +++ b/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/springdata/SpringDataJpaBenchmark.java @@ -0,0 +1,70 @@ +/* + * Copyright 2019 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.microbenchmark.jpa.springdata; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.infra.Blackhole; +import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark; +import org.springframework.data.microbenchmark.jpa.JpaFixture; + +/** + * @author Oliver Drotbohm + */ +public class SpringDataJpaBenchmark extends AbstractMicrobenchmark { + + private JpaFixture fixture; + private JpaBookRepository repository; + + @Setup + public void setUp() { + + this.fixture = new JpaFixture(); + this.repository = fixture.getContext().getBean(JpaBookRepository.class); + } + + @Benchmark + public void findByTitle(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + sink.consume(repository.findDerivedByTitle("title0")); + }); + } + + @Benchmark + public void findByTitleDeclared(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + sink.consume(repository.findDeclaredByTitle("title0")); + }); + } + + @Benchmark + public void findByTitleOptional(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + sink.consume(repository.findOptionalDerivedByTitle("title0")); + }); + } + + @Benchmark + public void findAll(Blackhole sink) { + + fixture.withNonTransactionalEntityManager(em -> { + sink.consume(repository.findAll()); + }); + } +} diff --git a/benchmark/relational/src/main/resources/application-jdbc.properties b/benchmark/relational/src/main/resources/application-jdbc.properties new file mode 100644 index 0000000..d580454 --- /dev/null +++ b/benchmark/relational/src/main/resources/application-jdbc.properties @@ -0,0 +1 @@ +spring.data.jpa.repositories.enabled=false diff --git a/benchmark/relational/src/main/resources/application-jpa.properties b/benchmark/relational/src/main/resources/application-jpa.properties new file mode 100644 index 0000000..5836638 --- /dev/null +++ b/benchmark/relational/src/main/resources/application-jpa.properties @@ -0,0 +1,2 @@ +spring.jpa.hibernate.ddl-auto=update +spring.data.jdbc.repositories.enabled=false diff --git a/benchmark/support/pom.xml b/benchmark/support/pom.xml index cfcbe9f..de98938 100644 --- a/benchmark/support/pom.xml +++ b/benchmark/support/pom.xml @@ -5,7 +5,7 @@ 4.0.0 - org.springframework.data + org.springframework.data.benchmark spring-data-benchmark-parent 2.2.0.BUILD-SNAPSHOT