├── README.adoc
├── benchmark
├── relational
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ ├── application-jdbc.properties
│ │ │ ├── application-jpa.properties
│ │ │ ├── application-r2dbc.properties
│ │ │ ├── schema-postgres.sql
│ │ │ ├── schema-h2.sql
│ │ │ ├── application-h2-in-memory.properties
│ │ │ ├── data-postgres.sql
│ │ │ ├── data-h2.sql
│ │ │ ├── application-h2.properties
│ │ │ └── application-postgres.properties
│ │ │ └── java
│ │ │ └── org
│ │ │ └── springframework
│ │ │ └── data
│ │ │ └── microbenchmark
│ │ │ ├── jdbc
│ │ │ ├── BenchmarkMain.java
│ │ │ ├── Book.java
│ │ │ ├── JdbcBookRepository.java
│ │ │ ├── JdbcBenchmark.java
│ │ │ └── JdbcFixture.java
│ │ │ ├── jpa
│ │ │ ├── Book.java
│ │ │ ├── JpaBookRepository.java
│ │ │ ├── JpaFixture.java
│ │ │ └── JpaBenchmark.java
│ │ │ ├── r2dbc
│ │ │ ├── Book.java
│ │ │ ├── R2dbcFixture.java
│ │ │ ├── R2dbcBookRepository.java
│ │ │ └── R2dbcBenchmark.java
│ │ │ └── FixtureUtils.java
│ ├── pom.xml
│ └── readme.adoc
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── support
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ ├── META-INF
│ │ │ │ └── services
│ │ │ │ │ └── jmh.mbr.core.ResultsWriterFactory
│ │ │ └── logback.xml
│ │ │ └── java
│ │ │ └── org
│ │ │ └── springframework
│ │ │ └── data
│ │ │ └── microbenchmark
│ │ │ └── common
│ │ │ ├── MicrobenchmarkResultsWriterFactory.java
│ │ │ ├── AbstractMicrobenchmark.java
│ │ │ ├── HttpResultsWriter.java
│ │ │ └── MongoResultsWriter.java
│ └── pom.xml
├── mongodb
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── org
│ │ │ └── springframework
│ │ │ └── data
│ │ │ └── microbenchmark
│ │ │ └── mongodb
│ │ │ ├── Constants.java
│ │ │ ├── MongoDbBookRepository.java
│ │ │ ├── Book.java
│ │ │ ├── MongoDbFixture.java
│ │ │ ├── convert
│ │ │ ├── DbRefMappingBenchmark.java
│ │ │ └── MappingMongoConverterBenchmark.java
│ │ │ ├── CallbacksBenchmark.java
│ │ │ ├── MongoDbBenchmark.java
│ │ │ ├── AfterConvertCallbacksBenchmark.java
│ │ │ └── ProjectionsBenchmark.java
│ └── pom.xml
├── commons
│ ├── src
│ │ └── main
│ │ │ ├── kotlin
│ │ │ └── org
│ │ │ │ └── springframework
│ │ │ │ └── data
│ │ │ │ └── microbenchmark
│ │ │ │ └── commons
│ │ │ │ └── convert
│ │ │ │ └── MyDataClass.kt
│ │ │ └── java
│ │ │ └── org
│ │ │ └── springframework
│ │ │ └── data
│ │ │ └── microbenchmark
│ │ │ └── commons
│ │ │ └── convert
│ │ │ ├── DefaultTypeMapperBenchmark.java
│ │ │ └── TypicalEntityReaderBenchmark.java
│ └── pom.xml
├── redis
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── org
│ │ └── springframework
│ │ └── data
│ │ └── microbenchmark
│ │ └── redis
│ │ └── ReactiveRedisTemplateBenchmark.java
├── README.md
├── pom.xml
├── mvnw.cmd
└── mvnw
├── .gitignore
└── LICENSE.txt
/README.adoc:
--------------------------------------------------------------------------------
1 | = Spring Data Development Tools
2 |
3 | A collection of tools to support Spring Data development.
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-jdbc.properties:
--------------------------------------------------------------------------------
1 | spring.data.jpa.repositories.enabled=false
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .settings/
3 | .project
4 | .classpath
5 | .factorypath
6 | .springBeans
7 | .idea/
8 | *.iml
9 | build/
10 |
--------------------------------------------------------------------------------
/benchmark/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-projects/spring-data-dev-tools/HEAD/benchmark/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-jpa.properties:
--------------------------------------------------------------------------------
1 | spring.jpa.hibernate.ddl-auto=create-drop
2 | spring.data.jdbc.repositories.enabled=false
3 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-r2dbc.properties:
--------------------------------------------------------------------------------
1 | spring.data.jpa.repositories.enabled=false
2 | spring.data.jdbc.repositories.enabled=false
3 |
--------------------------------------------------------------------------------
/benchmark/support/src/main/resources/META-INF/services/jmh.mbr.core.ResultsWriterFactory:
--------------------------------------------------------------------------------
1 | org.springframework.data.microbenchmark.common.MicrobenchmarkResultsWriterFactory
2 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/schema-postgres.sql:
--------------------------------------------------------------------------------
1 | drop table if exists Book;
2 | create table Book (
3 | id serial primary key,
4 | title varchar(255),
5 | pages integer not null
6 | );
7 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/schema-h2.sql:
--------------------------------------------------------------------------------
1 | drop table Book if exists;
2 | create table Book (
3 | id bigint not null auto_increment,
4 | title varchar(255),
5 | pages integer not null,
6 | primary key (id)
7 | );
8 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-h2-in-memory.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:benchmark;DB_CLOSE_DELAY=-1
2 | spring.sql.init.platform=h2
3 | spring.r2dbc.platform=h2
4 |
5 |
6 | logging.level.org.springframework.boot.autoconfigure=DEBUG
--------------------------------------------------------------------------------
/benchmark/support/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d %5p %40.40c:%4L - %m%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/data-postgres.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO Book(title, pages) VALUES ('title0', 0);
2 | INSERT INTO Book(title, pages) VALUES ('title1', 1);
3 | INSERT INTO Book(title, pages) VALUES ('title2', 2);
4 | INSERT INTO Book(title, pages) VALUES ('title3', 3);
5 | INSERT INTO Book(title, pages) VALUES ('title4', 4);
6 | INSERT INTO Book(title, pages) VALUES ('title5', 5);
7 | INSERT INTO Book(title, pages) VALUES ('title6', 6);
8 | INSERT INTO Book(title, pages) VALUES ('title7', 7);
9 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/data-h2.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO Book (title, pages) VALUES ('title1', 1);
2 | INSERT INTO Book (title, pages) VALUES ('title0', 0);
3 | INSERT INTO Book (title, pages) VALUES ('title2', 2);
4 | INSERT INTO Book (title, pages) VALUES ('title3', 3);
5 | INSERT INTO Book (title, pages) VALUES ('title4', 4);
6 | INSERT INTO Book (title, pages) VALUES ('title5', 5);
7 | INSERT INTO Book (title, pages) VALUES ('title6', 6);
8 | INSERT INTO Book (title, pages) VALUES ('title7', 7);
9 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-h2.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:tcp://localhost:9092/~/benchmark
2 | spring.datasource.username=sa
3 | spring.datasource.password=
4 | spring.sql.init.platform=h2
5 | spring.sql.init.mode=always
6 |
7 | spring.r2dbc.url=r2dbc:h2:tcp://localhost:9092/~/benchmark
8 | spring.r2dbc.username=sa
9 | spring.r2dbc.password=
10 | spring.r2dbc.platform=h2
11 | spring.r2dbc.initialization-mode=always
12 |
13 | logging.level.org.springframework.boot.autoconfigure=DEBUG
--------------------------------------------------------------------------------
/benchmark/relational/src/main/resources/application-postgres.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:postgresql://localhost:5455/benchmark
2 | # this is intentionally non standard property user instead of username, since we are using PGSimpleDatasource, which has a user, but no username property
3 | spring.datasource.user=postgres
4 | spring.datasource.password=secret
5 | spring.sql.init.platform=postgres
6 | spring.sql.init.mode=always
7 |
8 | spring.r2dbc.url=r2dbc:postgresql://localhost:5432/benchmark
9 | spring.r2dbc.platform=postgres
10 | spring.r2dbc.username=postgres
11 | spring.r2dbc.password=secret
12 | spring.r2dbc.initialization-mode=always
13 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/BenchmarkMain.java:
--------------------------------------------------------------------------------
1 | package org.springframework.data.microbenchmark.jdbc;
2 |
3 | import org.openjdk.jmh.infra.Blackhole;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | public class BenchmarkMain {
7 | public static void main(String[] args) throws Exception {
8 | JdbcBenchmark jdbcBenchmark = new JdbcBenchmark();
9 | jdbcBenchmark.profile = "postgres";
10 | jdbcBenchmark.setUp();
11 | jdbcBenchmark.convertWithSpringData(new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/benchmark/mongodb/src/main/java/org/springframework/data/microbenchmark/mongodb/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.mongodb;
17 |
18 | import lombok.experimental.UtilityClass;
19 |
20 | /**
21 | * @author Oliver Drotbohm
22 | */
23 | @UtilityClass
24 | class Constants {
25 |
26 | public static final int NUMBER_OF_BOOKS = 8;
27 | }
28 |
--------------------------------------------------------------------------------
/benchmark/commons/src/main/kotlin/org/springframework/data/microbenchmark/commons/convert/MyDataClass.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2022 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.microbenchmark.commons.convert
17 |
18 | /**
19 | * @author Mark Paluch
20 | */
21 | data class MyDataClass(val firstname: String, val lastname: String)
22 |
23 | data class MyDataClassWithDefaulting(val firstname: String, val lastname: String, val foo: Int = 42)
24 |
--------------------------------------------------------------------------------
/benchmark/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
19 |
--------------------------------------------------------------------------------
/benchmark/redis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 |
9 | org.springframework.data.benchmark
10 | spring-data-benchmark-parent
11 | 3.3.0-SNAPSHOT
12 |
13 |
14 | spring-data-benchmark-redis
15 |
16 | Spring Data Benchmarks - Redis Microbenchmarks
17 |
18 |
19 |
20 |
21 | ${project.groupId}
22 | spring-data-benchmark-support
23 |
24 |
25 |
26 | org.springframework.data
27 | spring-data-redis
28 |
29 |
30 |
31 | io.lettuce
32 | lettuce-core
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/Book.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.jdbc;
17 |
18 | import lombok.AllArgsConstructor;
19 | import lombok.Data;
20 |
21 | import org.springframework.data.annotation.Id;
22 | import org.springframework.data.relational.core.mapping.Table;
23 |
24 | /**
25 | * @author Oliver Drotbohm
26 | */
27 | @Data
28 | @AllArgsConstructor
29 | @Table
30 | public class Book {
31 |
32 | private @Id Long id;
33 | private String title;
34 | private int pages;
35 | }
36 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/Book.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.jpa;
17 |
18 | import lombok.AllArgsConstructor;
19 | import lombok.Data;
20 | import lombok.NoArgsConstructor;
21 |
22 | import jakarta.persistence.Entity;
23 | import jakarta.persistence.GeneratedValue;
24 | import jakarta.persistence.Id;
25 |
26 | /**
27 | * @author Oliver Drotbohm
28 | */
29 | @Data
30 | @Entity
31 | @AllArgsConstructor
32 | @NoArgsConstructor
33 | public class Book {
34 |
35 | private @GeneratedValue @Id Long id;
36 | private String title;
37 | private int pages;
38 | }
39 |
--------------------------------------------------------------------------------
/benchmark/commons/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | org.springframework.data.benchmark
9 | spring-data-benchmark-parent
10 | 3.3.0-SNAPSHOT
11 |
12 |
13 | spring-data-benchmark-commons
14 |
15 | Spring Data Benchmarks - Commons Microbenchmarks
16 |
17 |
18 |
19 |
20 | ${project.groupId}
21 | spring-data-benchmark-support
22 |
23 |
24 |
25 | org.springframework.data
26 | spring-data-commons
27 |
28 |
29 |
30 | org.jetbrains.kotlin
31 | kotlin-stdlib-jdk8
32 | ${kotlin}
33 |
34 |
35 |
36 | org.jetbrains.kotlin
37 | kotlin-reflect
38 | ${kotlin}
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/benchmark/mongodb/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | org.springframework.data.benchmark
9 | spring-data-benchmark-parent
10 | 3.3.0-SNAPSHOT
11 |
12 |
13 | spring-data-benchmark-mongodb
14 |
15 | Spring Data Benchmarks - MongoDB Microbenchmarks
16 |
17 |
18 |
19 |
20 | ${project.groupId}
21 | spring-data-benchmark-support
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-mongodb
27 |
28 |
29 |
30 | org.mockito
31 | mockito-core
32 |
33 |
34 |
35 | de.flapdoodle.embed
36 | de.flapdoodle.embed.mongo
37 | 4.12.2
38 | runtime
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/benchmark/mongodb/src/main/java/org/springframework/data/microbenchmark/mongodb/MongoDbBookRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.mongodb;
17 |
18 | import java.util.Optional;
19 |
20 | import org.bson.types.ObjectId;
21 | import org.springframework.data.mongodb.repository.Query;
22 | import org.springframework.data.repository.CrudRepository;
23 |
24 | /**
25 | * @author Oliver Drotbohm
26 | */
27 | interface MongoDbBookRepository extends CrudRepository {
28 |
29 | @Query("{ \"title\" : $0 }")
30 | Book findDeclaredByTitle(String title);
31 |
32 | Book findDerivedByTitle(String title);
33 |
34 | Optional findOptionalDerivedByTitle(String title);
35 | }
36 |
--------------------------------------------------------------------------------
/benchmark/support/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | org.springframework.data.benchmark
9 | spring-data-benchmark-parent
10 | 3.3.0-SNAPSHOT
11 |
12 |
13 | spring-data-benchmark-support
14 |
15 | Spring Data Benchmarks - Support
16 |
17 | SpringDataBenchmarkSupport
18 |
19 |
20 |
21 |
22 |
23 | org.springframework.data
24 | spring-data-mongodb
25 |
26 |
27 |
28 | org.mongodb
29 | mongodb-driver-sync
30 |
31 |
32 |
33 | com.github.mp911de.microbenchmark-runner
34 | microbenchmark-runner-junit4
35 |
36 |
37 |
38 | net.minidev
39 | json-smart
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/benchmark/support/src/main/java/org/springframework/data/microbenchmark/common/MicrobenchmarkResultsWriterFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2022 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.microbenchmark.common;
17 |
18 | import jmh.mbr.core.ResultsWriter;
19 | import jmh.mbr.core.ResultsWriterFactory;
20 |
21 | /**
22 | * {@link ResultsWriterFactory} plugin via {@link java.util.ServiceLoader}.
23 | *
24 | * @author Mark Paluch
25 | */
26 | public class MicrobenchmarkResultsWriterFactory implements ResultsWriterFactory {
27 |
28 | @Override
29 | public ResultsWriter forUri(String uri) {
30 |
31 | if (uri.startsWith("http")) {
32 | return new HttpResultsWriter(uri);
33 | }
34 |
35 | if (uri.startsWith("mongo")) {
36 | return new MongoResultsWriter(uri);
37 | }
38 |
39 | return null;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/r2dbc/Book.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.r2dbc;
17 |
18 | import lombok.AccessLevel;
19 | import lombok.RequiredArgsConstructor;
20 | import lombok.Value;
21 | import lombok.With;
22 |
23 | import org.springframework.data.annotation.Id;
24 | import org.springframework.data.annotation.PersistenceConstructor;
25 |
26 | /**
27 | * @author Oliver Drotbohm
28 | */
29 | @Value
30 | @RequiredArgsConstructor(access = AccessLevel.PACKAGE, onConstructor = @__(@PersistenceConstructor))
31 | class Book {
32 |
33 | @With(AccessLevel.PACKAGE) @Id Long id;
34 | String title;
35 | int pages;
36 |
37 | public Book(String title, int pages) {
38 |
39 | this.id = null;
40 | this.title = title;
41 | this.pages = pages;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/benchmark/mongodb/src/main/java/org/springframework/data/microbenchmark/mongodb/Book.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.mongodb;
17 |
18 | import lombok.AllArgsConstructor;
19 | import lombok.Value;
20 |
21 | import org.bson.types.ObjectId;
22 |
23 | import org.springframework.data.annotation.Id;
24 | import org.springframework.data.annotation.PersistenceConstructor;
25 | import org.springframework.data.mongodb.core.mapping.Document;
26 |
27 | /**
28 | * @author Oliver Drotbohm
29 | */
30 | @Value
31 | @Document
32 | @AllArgsConstructor(onConstructor = @__(@PersistenceConstructor))
33 | public class Book {
34 |
35 | @Id ObjectId id;
36 | String title;
37 | int pages;
38 |
39 | public Book(String title, int pages) {
40 |
41 | this.id = ObjectId.get();
42 | this.title = title;
43 | this.pages = pages;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/r2dbc/R2dbcFixture.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.r2dbc;
17 |
18 | import lombok.Getter;
19 |
20 | import org.springframework.boot.autoconfigure.SpringBootApplication;
21 | import org.springframework.context.ConfigurableApplicationContext;
22 | import org.springframework.data.microbenchmark.FixtureUtils;
23 |
24 | /**
25 | * Test fixture for JDBC and Spring Data JDBC benchmarks.
26 | *
27 | * @author Oliver Drotbohm
28 | */
29 | public class R2dbcFixture {
30 |
31 | private final @Getter ConfigurableApplicationContext context;
32 |
33 | public R2dbcFixture(String database) {
34 | this.context = FixtureUtils.createContext(R2dbcApplication.class, "r2dbc", database);
35 | }
36 |
37 | @SpringBootApplication
38 | static class R2dbcApplication {}
39 | }
40 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/FixtureUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark;
17 |
18 | import lombok.experimental.UtilityClass;
19 |
20 | import java.util.Arrays;
21 | import java.util.Collections;
22 |
23 | import org.springframework.boot.SpringApplication;
24 | import org.springframework.context.ConfigurableApplicationContext;
25 |
26 | @UtilityClass
27 | public class FixtureUtils {
28 |
29 | public static final int NUMBER_OF_BOOKS = 8;
30 |
31 | public static ConfigurableApplicationContext createContext(Class> configuration, String api, String database) {
32 |
33 | SpringApplication application = new SpringApplication();
34 | application.addPrimarySources(Collections.singletonList(configuration));
35 | application.setLazyInitialization(true);
36 | application.setAdditionalProfiles(api, database);
37 |
38 | System.out.println("Activating profiles: " + Arrays.asList(api, database).toString());
39 |
40 | return application.run();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaBookRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.jpa;
17 |
18 | import java.util.Optional;
19 |
20 | import org.springframework.data.jpa.repository.Query;
21 | import org.springframework.data.repository.CrudRepository;
22 | import org.springframework.transaction.annotation.Transactional;
23 |
24 | /**
25 | * @author Oliver Drotbohm
26 | */
27 | interface JpaBookRepository extends CrudRepository {
28 |
29 | static final String BY_TITLE_JPQL = "select b from Book b where b.title = :title";
30 |
31 | @Query(BY_TITLE_JPQL)
32 | Book findDeclaredByTitle(String title);
33 |
34 | @Transactional(readOnly = true)
35 | @Query(BY_TITLE_JPQL)
36 | Book findTransactionalDeclaredByTitle(String title);
37 |
38 | Book findDerivedByTitle(String title);
39 |
40 | @Transactional(readOnly = true)
41 | Book findTransactionalDerivedByTitle(String title);
42 |
43 | Optional findOptionalDerivedByTitle(String title);
44 | }
45 |
--------------------------------------------------------------------------------
/benchmark/support/src/main/java/org/springframework/data/microbenchmark/common/AbstractMicrobenchmark.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2022 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.microbenchmark.common;
17 |
18 | import jmh.mbr.junit4.Microbenchmark;
19 |
20 | import org.junit.runner.RunWith;
21 | import org.openjdk.jmh.annotations.Fork;
22 | import org.openjdk.jmh.annotations.Measurement;
23 | import org.openjdk.jmh.annotations.Scope;
24 | import org.openjdk.jmh.annotations.State;
25 | import org.openjdk.jmh.annotations.Warmup;
26 |
27 | /**
28 | * Base class for microbenchmarks providing default JMH settings and allowing execution through JUnit.
29 | *
30 | * @author Christoph Strobl
31 | * @author Mark Paluch
32 | * @see Microbenchmark
33 | */
34 | @Warmup(iterations = 10, time = 2)
35 | @Measurement(iterations = 10, time = 2)
36 | @Fork(value = 1, jvmArgs = { "-server", "-XX:+HeapDumpOnOutOfMemoryError", "-Xms1024m", "-Xmx1024m",
37 | "-XX:MaxDirectMemorySize=1024m", "-noverify" })
38 | @State(Scope.Thread)
39 | @RunWith(Microbenchmark.class)
40 | public abstract class AbstractMicrobenchmark {
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/r2dbc/R2dbcBookRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.r2dbc;
17 |
18 | import reactor.core.publisher.Flux;
19 | import reactor.core.publisher.Mono;
20 |
21 | import org.springframework.data.r2dbc.repository.Query;
22 | import org.springframework.data.r2dbc.repository.R2dbcRepository;
23 | import org.springframework.transaction.annotation.Propagation;
24 | import org.springframework.transaction.annotation.Transactional;
25 |
26 | /**
27 | * A repository for {@link Book} instances.
28 | *
29 | * @author Oliver Drotbohm
30 | */
31 | interface R2dbcBookRepository extends R2dbcRepository {
32 |
33 | static final String BY_TITLE = "SELECT id, title, pages FROM Book where title = :title";
34 |
35 | @Transactional(propagation = Propagation.NOT_SUPPORTED)
36 | Flux findAll();
37 |
38 | @Query(BY_TITLE)
39 | Mono findByTitle(String title);
40 |
41 | @Transactional(readOnly = true)
42 | @Query(BY_TITLE)
43 | Mono findTransactionalByTitle(String title);
44 | }
45 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jdbc/JdbcBookRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.jdbc;
17 |
18 | import java.util.Optional;
19 |
20 | import org.springframework.data.jdbc.repository.query.Query;
21 | import org.springframework.data.repository.CrudRepository;
22 | import org.springframework.transaction.annotation.Propagation;
23 | import org.springframework.transaction.annotation.Transactional;
24 |
25 | /**
26 | * A repository for {@link Book} instances.
27 | *
28 | * @author Oliver Drotbohm
29 | */
30 | interface JdbcBookRepository extends CrudRepository {
31 |
32 | static final String BY_TITLE = "SELECT id, title, pages FROM Book where title = :title";
33 |
34 | @Transactional(propagation = Propagation.NOT_SUPPORTED)
35 | Iterable findAll();
36 |
37 | @Query(BY_TITLE)
38 | Book findByTitle(String title);
39 |
40 | @Transactional(readOnly = true)
41 | @Query(BY_TITLE)
42 | Book findTransactionalByTitle(String title);
43 |
44 | @Query(BY_TITLE)
45 | Optional findOptionalByTitle(String title);
46 | }
47 |
--------------------------------------------------------------------------------
/benchmark/mongodb/src/main/java/org/springframework/data/microbenchmark/mongodb/MongoDbFixture.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.mongodb;
17 |
18 | import lombok.Getter;
19 |
20 | import java.util.Collections;
21 | import java.util.stream.IntStream;
22 |
23 | import org.springframework.boot.SpringApplication;
24 | import org.springframework.boot.autoconfigure.SpringBootApplication;
25 | import org.springframework.context.ConfigurableApplicationContext;
26 | import org.springframework.data.mongodb.core.MongoOperations;
27 |
28 | /**
29 | * @author Oliver Drotbohm
30 | */
31 | class MongoDbFixture {
32 |
33 | private final @Getter ConfigurableApplicationContext context;
34 |
35 | MongoDbFixture() {
36 |
37 | SpringApplication application = new SpringApplication();
38 | application.addPrimarySources(Collections.singletonList(MongoDbApplication.class));
39 | application.setAdditionalProfiles("jpa");
40 | application.setLazyInitialization(true);
41 |
42 | this.context = application.run();
43 |
44 | MongoOperations operations = context.getBean(MongoOperations.class);
45 |
46 | operations.dropCollection(Book.class);
47 |
48 | IntStream.range(0, Constants.NUMBER_OF_BOOKS) //
49 | .mapToObj(it -> new Book("title" + it, it)) //
50 | .forEach(operations::save);
51 | }
52 |
53 | @SpringBootApplication
54 | static class MongoDbApplication {}
55 | }
56 |
--------------------------------------------------------------------------------
/benchmark/relational/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | org.springframework.data.benchmark
9 | spring-data-benchmark-parent
10 | 3.3.0-SNAPSHOT
11 |
12 |
13 | spring-data-benchmark-relational
14 |
15 | Spring Data Benchmarks - Relational Microbenchmarks
16 |
17 |
18 |
19 |
20 | ${project.groupId}
21 | spring-data-benchmark-support
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-data-jdbc
32 |
33 |
34 |
35 | com.h2database
36 | h2
37 |
38 |
39 |
40 | org.postgresql
41 | postgresql
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-data-r2dbc
49 |
50 |
51 |
52 | io.r2dbc
53 | r2dbc-h2
54 |
55 |
56 |
57 | org.postgresql
58 | r2dbc-postgresql
59 |
60 |
61 |
62 |
63 |
64 | org.mockito
65 | mockito-core
66 |
67 |
68 |
69 | com.mockrunner
70 | mockrunner-jdbc
71 | 2.0.1
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/benchmark/relational/readme.adoc:
--------------------------------------------------------------------------------
1 | = Benchmarks for relational data access with Spring Data
2 |
3 | This benchmark evaluates various options of relation data access in the Spring Data project family:
4 |
5 | - JDBC and Spring Data JDBC
6 | - JPA and Spring Data JPA
7 |
8 | The primary purpose of the benchmark is to help the team detect degradations in performance quickly or verify optimizations made in various areas of the libraries.
9 | It also helps justifying differences between numbers in rather clean room contexts (an embedded database) and scenarios that use a more realistic setup like a locally running database.
10 | That difference alone will help reasoning about the real-world impact of an optimization or degradation.
11 |
12 | == Benchmark model
13 |
14 | The benchmarks use a very simple model of a book with a title and pages attribute.
15 | We deliberately chose a simple model as the benchmarks are supposed to measure the overhead the Spring Data mapping and repository infrastructure adds on top of the raw JDBC and JPA alternatives.
16 | There are two major benchmark operations:
17 |
18 | 1. Finding all books (8 items)
19 | 2. Finding a single book by title.
20 |
21 | There are different flavors of those operations to measure the impact of different setups to execute them:
22 |
23 | - the effect of read-only transactions in the find all case
24 | - the difference between derived and declared queries in JPA
25 |
26 | == Infrastructure
27 |
28 | The benchmarks are run against the following databases:
29 |
30 | - In-memory H2
31 | - A locally running H2 (port 9092, database name `benchmark`, user `sa`, empty password).
32 | You may start such a server by running
33 | +
34 | ```
35 | java -cp ~/.m2/repository/com/h2database/h2/2.2.224/h2-2.2.224.jar org.h2.tools.Server -ifNotExists
36 | ```
37 | assuming you have a local maven repo in the default location.
38 | - A locally running Postgres (port 5455, database name `benchmark`, user: postgres, password: secret). You may start such a server by running
39 | +
40 | ```
41 | docker run --name myPostgresDb -p 5455:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=benchmark -d postgres
42 | ```
43 |
44 | The settings can be adapted by tweaking corresponding `application-$database.properties` file in `src/main/resources`.
45 |
--------------------------------------------------------------------------------
/benchmark/relational/src/main/java/org/springframework/data/microbenchmark/jpa/JpaFixture.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2022 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.microbenchmark.jpa;
17 |
18 | import lombok.Getter;
19 |
20 | import java.util.function.Consumer;
21 | import java.util.stream.IntStream;
22 |
23 | import jakarta.persistence.EntityManager;
24 |
25 | import org.springframework.boot.autoconfigure.SpringBootApplication;
26 | import org.springframework.context.ConfigurableApplicationContext;
27 | import org.springframework.data.microbenchmark.FixtureUtils;
28 | import org.springframework.transaction.PlatformTransactionManager;
29 | import org.springframework.transaction.TransactionStatus;
30 | import org.springframework.transaction.support.DefaultTransactionDefinition;
31 |
32 | /**
33 | * Test fixture for JPA and Spring Data JPA benchmarks.
34 | *
35 | * @author Oliver Drotbohm
36 | */
37 | class JpaFixture {
38 |
39 | private final @Getter ConfigurableApplicationContext context;
40 |
41 | JpaFixture(String database) {
42 |
43 | this.context = FixtureUtils.createContext(JpaApplication.class, "jpa", database);
44 |
45 | withTransactionalEntityManager(em -> {
46 |
47 | IntStream.range(0, FixtureUtils.NUMBER_OF_BOOKS) //
48 | .mapToObj(it -> new Book(null, "title" + it, it)) //
49 | .forEach(em::persist);
50 | });
51 | }
52 |
53 | private void withTransactionalEntityManager(Consumer consumer) {
54 |
55 | PlatformTransactionManager manager = context.getBean(PlatformTransactionManager.class);
56 | TransactionStatus status = manager.getTransaction(new DefaultTransactionDefinition());
57 |
58 | EntityManager em = context.getBean(EntityManager.class);
59 |
60 | consumer.accept(em);
61 |
62 | em.flush();
63 | manager.commit(status);
64 | em.close();
65 | }
66 |
67 | @SpringBootApplication
68 | static class JpaApplication {}
69 | }
70 |
--------------------------------------------------------------------------------
/benchmark/README.md:
--------------------------------------------------------------------------------
1 | # Benchmarks
2 |
3 | Benchmarks are based on [JMH](https://openjdk.java.net/projects/code-tools/jmh/).
4 |
5 | # Running Benchmarks
6 |
7 | To run the benchmarks with default settings use:
8 |
9 | ```bash
10 | mvn clean test
11 | ```
12 |
13 | A basic report will be printed to the CLI.
14 |
15 | ```bash
16 | # Run complete. Total time: 00:00:15
17 |
18 | Benchmark Mode Cnt Score Error Units
19 | MappingMongoConverterBenchmark.readObject thrpt 10 1920157,631 ± 64310,809 ops/s
20 | MappingMongoConverterBenchmark.writeObject thrpt 10 782732,857 ± 53804,130 ops/s
21 | ```
22 |
23 | ## Running all Benchmarks of a specific class
24 |
25 | To run all Benchmarks of a specific class, just provide its simple class name via the `benchmark` command line argument.
26 |
27 | ```bash
28 | mvn clean test -D benchmark=MappingMongoConverterBenchmark
29 | ```
30 |
31 | ## Running a single Benchmark
32 |
33 | To run a single Benchmark provide its containing class simple name followed by `#` and the method name via the `benchmark` command line argument.
34 |
35 | ```bash
36 | mvn clean test -D benchmark=MappingMongoConverterBenchmark#readObjectWith2Properties
37 | ```
38 |
39 | # Saving Benchmark Results
40 |
41 | A detailed benchmark report is stored in JSON format in the `/target/reports/performance` directory.
42 | To store the report in a different location use the `benchmarkReportDir` command line argument.
43 |
44 | ## MongoDB
45 |
46 | Results can be directly piped to MongoDB by providing a valid [Connection String](https://docs.mongodb.com/manual/reference/connection-string/) via the `publishTo` command line argument.
47 |
48 | ```bash
49 | mvn clean test -D publishTo=mongodb://127.0.0.1:27017
50 | ```
51 |
52 | NOTE: If the uri does not explicitly define a database the default `spring-data-mongodb-benchmarks` is used.
53 |
54 | ## HTTP Endpoint
55 |
56 | The benchmark report can also be posted as `application/json` to an HTTP Endpoint by providing a valid URl via the `publishTo` command line argument.
57 |
58 | ```bash
59 | mvn clean test -D publishTo=http://127.0.0.1:8080/capture-benchmarks
60 | ```
61 |
62 | # Customizing Benchmarks
63 |
64 | Following options can be set via command line.
65 |
66 | Option | Default Value
67 | --- | ---
68 | warmupIterations | 10
69 | warmupTime | 1 (seconds)
70 | measurementIterations | 10
71 | measurementTime | 1 (seconds)
72 | forks | 1
73 | benchmarkReportDir | /target/reports/performance (always relative to project root dir)
74 | benchmark | .* (single benchmark via `classname#benchmark`)
75 | publishTo | \[not set\] (mongodb-uri or http-endpoint)
76 |
--------------------------------------------------------------------------------
/benchmark/commons/src/main/java/org/springframework/data/microbenchmark/commons/convert/DefaultTypeMapperBenchmark.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2022 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.microbenchmark.commons.convert;
17 |
18 | import java.util.Collections;
19 | import java.util.Map;
20 |
21 | import org.openjdk.jmh.annotations.Benchmark;
22 | import org.springframework.data.convert.DefaultTypeMapper;
23 | import org.springframework.data.convert.TypeAliasAccessor;
24 | import org.springframework.data.mapping.Alias;
25 | import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark;
26 | import org.springframework.data.util.ClassTypeInformation;
27 | import org.springframework.data.util.TypeInformation;
28 |
29 | /**
30 | * Benchmark for {@link DefaultTypeMapper}.
31 | *
32 | * @author Mark Paluch
33 | */
34 | public class DefaultTypeMapperBenchmark extends AbstractMicrobenchmark {
35 |
36 | private static final DefaultTypeMapper