“本地环境:IDEA 2018.3.6
”
“jmh 1.21 。本地使用 1.22 失败,可能是 windows 10 下面使用了阿里巴巴的 Maven 镜像源有 bug
”
上一篇算是一次失败的尝试,后来笔者又查阅了别人的文章, 分享一个可用的
运行方法:
右键 AppTest.java,选择 run
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xxx</groupId>
<artifactId>xxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>covid19</name>
<description>spider to grathering infected covid19</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-api</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>0.7.7</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
AppTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.springboot.entity.SnapShot;
import com.springboot.service.CacheService;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime) // 测试方法平均执行时间
@OutputTimeUnit(TimeUnit.MILLISECONDS) // 输出结果的时间粒度为微秒
@State(Scope.Thread)
public class AppTest
{
private ConfigurableApplicationContext context;
final Gson gson = new Gson();
ObjectMapper mapper = new ObjectMapper();
CacheService cacheService;
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder().include(AppTest.class.getName()+".*")
.warmupIterations(1).measurementIterations(20).forks(2).build();
new Runner(options).run();
}
/**
* setup初始化容器的时候只执行一次
*/
@Setup(Level.Trial)
public void init(){
context = SpringApplication.run(App.class);
cacheService = context.getBean(CacheService.class);
}
@Benchmark
public void testGetPojo()
{
Map<String, SnapShot> map = cacheService.getCacheMap("snapshot", SnapShot.class);
}
}
两个进程,分别热身一起,每个进程跑 20 次
application.properties
logging.level.root=info
logging.file.path=logs
org.springfromework=info
spring.application.name=covid
spring.redis.timeout=5000
spring.redis.jedis.pool.max-active=1000
spring.redis.jedis.pool.max-idle=300
spring.redis.jedis.pool.max-wait=-1
spring.redis.jedis.pool.min-idle=30000
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-wait=10000
spring.redis.lettuce.pool.min-idle=0
spring.redis.lettuce.shutdown-timeout=100
spring.redis.host=127.0.0.1
spring.redis.password=xxx
import com.springboot.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@EnableCaching
@CacheConfig
@SpringBootApplication(scanBasePackages = "com.springboot",exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})
public class App
{
@Autowired
CacheService cacheService;
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
}
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.springboot.serializer.ProtostuffSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
RedisTemplate template = new RedisTemplate<>();
template.setConnectionFactory(factory);
//默认使用protoStuff序列化,比springRedisTemplate序列化效果好
//https://www.spldeolin.com/posts/redis-template-protostuff/
ProtostuffSerializer valueSerializer = new ProtostuffSerializer();
template.setDefaultSerializer(valueSerializer);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
/*hash字符串序列化方法*/
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
template.afterPropertiesSet();
return template;
}
}
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SnapShot {
@JsonIgnore
private Long id;
@JsonIgnore
private Integer distId;
@JsonProperty("name")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String distName;
private Integer confirm;
@JsonIgnore
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer suspect;
private Integer dead;
private Integer heal;
private Float weight;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Integer parentId;
@JsonIgnore
private String level;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String mapId;
private String updateTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SnapShot snapShot = (SnapShot) o;
return Objects.equal(distId, snapShot.distId) &&
Objects.equal(confirm, snapShot.confirm) &&
Objects.equal(suspect, snapShot.suspect) &&
Objects.equal(dead, snapShot.dead) &&
Objects.equal(heal, snapShot.heal)&&
Objects.equal(weight,snapShot.weight)&&
Objects.equal(level, snapShot.level)&&
Objects.equal(mapId,snapShot.mapId);
}
@Override
public int hashCode() {
return 0;
}
}
import com.dyuproject.protostuff.LinkedBuffer;
import com.dyuproject.protostuff.ProtostuffIOUtil;
import com.dyuproject.protostuff.Schema;
import com.dyuproject.protostuff.runtime.RuntimeSchema;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
public class ProtostuffSerializer implements RedisSerializer<Object> {
private final Schema<ProtoWrapper> schema;
private final ProtoWrapper wrapper;
private final LinkedBuffer buffer;
public ProtostuffSerializer() {
this.wrapper = new ProtoWrapper();
this.schema = RuntimeSchema.getSchema(ProtoWrapper.class);
this.buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
}
private boolean isEmpty(byte[] data) {
return (data == null || data.length == 0);
}
@Override
public byte[] serialize(Object t) throws SerializationException {
if (t == null) {
return new byte[0];
}
wrapper.data = t;
try {
return ProtostuffIOUtil.toByteArray(wrapper, schema, buffer);
} finally {
buffer.clear();
}
}
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
if (isEmpty(bytes)) {
return null;
}
ProtoWrapper newMessage = schema.newMessage();
ProtostuffIOUtil.mergeFrom(bytes, newMessage, schema);
return newMessage.data;
}
private static class ProtoWrapper {
public Object data;
}
}
public interface CacheService
{
<T> Map<String, T> getCacheMap(String key, Class<T> clazz);
}
@Override
public <T> Map<String, T> getCacheMap(String key, Class<T> clazz) {
Map<String, String> raw = redisTemplate.opsForHash().entries(key);
Map<String, T> map = Maps.newLinkedHashMapWithExpectedSize(raw.size());
for (Map.Entry<String, String> entry : raw.entrySet()) {
String hashKey = entry.getKey();
String value = entry.getValue();
map.put(hashKey, gson.fromJson(value, clazz));
}
return map;
}
以下是测试结果:
D:\develop\java\jdk1.8.0_181\bin\java.exe "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\lib\idea_rt.jar=58738:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\bin" -Dfile.encoding=UTF-8 -classpath D:\develop\java\jdk1.8.0_181\jre\lib\charsets.jar;D:\develop\java\jdk1.8.0_181\jre\lib\deploy.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\localedata.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\sunec.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;D:\develop\java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;D:\develop\java\jdk1.8.0_181\jre\lib\javaws.jar;D:\develop\java\jdk1.8.0_181\jre\lib\jce.jar;D:\develop\java\jdk1.8.0_181\jre\lib\jfr.jar;D:\develop\java\jdk1.8.0_181\jre\lib\jfxswt.jar;D:\develop\java\jdk1.8.0_181\jre\lib\jsse.jar;D:\develop\java\jdk1.8.0_181\jre\lib\management-agent.jar;D:\develop\java\jdk1.8.0_181\jre\lib\plugin.jar;D:\develop\java\jdk1.8.0_181\jre\lib\resources.jar;D:\develop\java\jdk1.8.0_181\jre\lib\rt.jar;E:\project\java\springBootJmh\target\test-classes;E:\project\java\springBootJmh\target\classes;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-pool2\2.5.0\commons-pool2-2.5.0.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-cache\2.2.4.RELEASE\spring-boot-starter-cache-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter\2.2.4.RELEASE\spring-boot-starter-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot\2.2.4.RELEASE\spring-boot-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-autoconfigure\2.2.4.RELEASE\spring-boot-autoconfigure-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-logging\2.2.4.RELEASE\spring-boot-starter-logging-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\develop\apache-maven-3.5.4\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\develop\apache-maven-3.5.4\repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\develop\apache-maven-3.5.4\repo\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-context-support\5.2.3.RELEASE\spring-context-support-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-beans\5.2.3.RELEASE\spring-beans-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-context\5.2.3.RELEASE\spring-context-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-expression\5.2.3.RELEASE\spring-expression-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-data-redis\2.2.4.RELEASE\spring-boot-starter-data-redis-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-redis\2.2.4.RELEASE\spring-data-redis-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-keyvalue\2.2.4.RELEASE\spring-data-keyvalue-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-commons\2.2.4.RELEASE\spring-data-commons-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-tx\5.2.3.RELEASE\spring-tx-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-oxm\5.2.3.RELEASE\spring-oxm-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-aop\5.2.3.RELEASE\spring-aop-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\develop\apache-maven-3.5.4\repo\io\lettuce\lettuce-core\5.2.1.RELEASE\lettuce-core-5.2.1.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-common\4.1.45.Final\netty-common-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-handler\4.1.45.Final\netty-handler-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-buffer\4.1.45.Final\netty-buffer-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-codec\4.1.45.Final\netty-codec-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-transport\4.1.45.Final\netty-transport-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-resolver\4.1.45.Final\netty-resolver-4.1.45.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\projectreactor\reactor-core\3.3.2.RELEASE\reactor-core-3.3.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-runtime\1.1.3\protostuff-runtime-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-collectionschema\1.1.3\protostuff-collectionschema-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-api\1.0.8\protostuff-api-1.0.8.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-core\1.0.8\protostuff-core-1.0.8.jar;D:\develop\apache-maven-3.5.4\repo\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-test\2.2.4.RELEASE\spring-boot-starter-test-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-test\2.2.4.RELEASE\spring-boot-test-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-test-autoconfigure\2.2.4.RELEASE\spring-boot-test-autoconfigure-2.2.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\develop\apache-maven-3.5.4\repo\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\develop\apache-maven-3.5.4\repo\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\develop\apache-maven-3.5.4\repo\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\develop\apache-maven-3.5.4\repo\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\develop\apache-maven-3.5.4\repo\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\jupiter\junit-jupiter\5.5.2\junit-jupiter-5.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\jupiter\junit-jupiter-api\5.5.2\junit-jupiter-api-5.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;D:\develop\apache-maven-3.5.4\repo\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\platform\junit-platform-commons\1.5.2\junit-platform-commons-1.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\jupiter\junit-jupiter-params\5.5.2\junit-jupiter-params-5.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\jupiter\junit-jupiter-engine\5.5.2\junit-jupiter-engine-5.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\junit\platform\junit-platform-engine\1.5.2\junit-platform-engine-1.5.2.jar;D:\develop\apache-maven-3.5.4\repo\org\mockito\mockito-junit-jupiter\3.1.0\mockito-junit-jupiter-3.1.0.jar;D:\develop\apache-maven-3.5.4\repo\org\assertj\assertj-core\3.13.2\assertj-core-3.13.2.jar;D:\develop\apache-maven-3.5.4\repo\org\hamcrest\hamcrest\2.1\hamcrest-2.1.jar;D:\develop\apache-maven-3.5.4\repo\org\mockito\mockito-core\3.1.0\mockito-core-3.1.0.jar;D:\develop\apache-maven-3.5.4\repo\net\bytebuddy\byte-buddy\1.10.6\byte-buddy-1.10.6.jar;D:\develop\apache-maven-3.5.4\repo\net\bytebuddy\byte-buddy-agent\1.10.6\byte-buddy-agent-1.10.6.jar;D:\develop\apache-maven-3.5.4\repo\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\develop\apache-maven-3.5.4\repo\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\develop\apache-maven-3.5.4\repo\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-core\5.2.3.RELEASE\spring-core-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-jcl\5.2.3.RELEASE\spring-jcl-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-test\5.2.3.RELEASE\spring-test-5.2.3.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;D:\develop\apache-maven-3.5.4\repo\com\google\guava\guava\20.0\guava-20.0.jar;D:\develop\apache-maven-3.5.4\repo\com\google\code\gson\gson\2.8.4\gson-2.8.4.jar;D:\develop\apache-maven-3.5.4\repo\org\modelmapper\modelmapper\0.7.7\modelmapper-0.7.7.jar;D:\develop\apache-maven-3.5.4\repo\org\openjdk\jmh\jmh-core\1.21\jmh-core-1.21.jar;D:\develop\apache-maven-3.5.4\repo\net\sf\jopt-simple\jopt-simple\4.6\jopt-simple-4.6.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-math3\3.2\commons-math3-3.2.jar;D:\develop\apache-maven-3.5.4\repo\org\openjdk\jmh\jmh-generator-annprocess\1.21\jmh-generator-annprocess-1.21.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-annotations\2.10.2\jackson-annotations-2.10.2.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-databind\2.10.2\jackson-databind-2.10.2.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-core\2.10.2\jackson-core-2.10.2.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.2\jackson-datatype-jsr310-2.10.2.jar;D:\develop\apache-maven-3.5.4\repo\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;D:\develop\apache-maven-3.5.4\repo\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\develop\apache-maven-3.5.4\repo\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar com.springboot.AppTest
# JMH version: 1.21
# VM version: JDK 1.8.0_181, Java HotSpot(TM) 64-Bit Server VM, 25.181-b13
# VM invoker: D:\develop\java\jdk1.8.0_181\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\lib\idea_rt.jar=58738:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\bin -Dfile.encoding=UTF-8
# Warmup: 1 iterations, 10 s each
# Measurement: 20 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: com.springboot.AppTest.testGetPojo
# Run progress: 0.00% complete, ETA 00:07:00
# Fork: 1 of 2
# Warmup Iteration 1: LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@1465433970
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.4.RELEASE)
2020-03-03 17:33:14.127 INFO 10892 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : Starting application on DESKTOP-AJTC6JT with PID 10892 (started by Administrator in E:\project\java\springBootJmh)
2020-03-03 17:33:14.130 INFO 10892 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2020-03-03 17:33:14.647 INFO 10892 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-03-03 17:33:14.652 INFO 10892 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-03-03 17:33:14.698 INFO 10892 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 24ms. Found 0 Redis repository interfaces.
2020-03-03 17:33:15.700 INFO 10892 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : Started application in 1.995 seconds (JVM running for 2.88)
2020-03-03 17:33:15.950 INFO 10892 --- [jo-jmh-worker-1] io.lettuce.core.EpollProvider : Starting without optional epoll library
2020-03-03 17:33:15.951 INFO 10892 --- [jo-jmh-worker-1] io.lettuce.core.KqueueProvider : Starting without optional kqueue library
8.290 ms/op
Iteration 1: 7.196 ms/op
Iteration 2: 7.229 ms/op
Iteration 3: 7.239 ms/op
Iteration 4: 7.529 ms/op
Iteration 5: 7.344 ms/op
Iteration 6: 7.131 ms/op
Iteration 7: 7.139 ms/op
Iteration 8: 7.158 ms/op
Iteration 9: 7.177 ms/op
Iteration 10: 7.106 ms/op
Iteration 11: 10.824 ms/op
Iteration 12: 7.170 ms/op
Iteration 13: 7.235 ms/op
Iteration 14: 7.019 ms/op
Iteration 15: 7.044 ms/op
Iteration 16: 7.146 ms/op
Iteration 17: 7.169 ms/op
Iteration 18: 7.106 ms/op
Iteration 19: 7.135 ms/op
Iteration 20: 7.032 ms/op
# Run progress: 50.00% complete, ETA 00:03:33
# Fork: 2 of 2
# Warmup Iteration 1: LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@591343639
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.4.RELEASE)
2020-03-03 17:36:47.587 INFO 3652 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : Starting application on DESKTOP-AJTC6JT with PID 3652 (started by Administrator in E:\project\java\springBootJmh)
2020-03-03 17:36:47.590 INFO 3652 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2020-03-03 17:36:47.999 INFO 3652 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-03-03 17:36:48.002 INFO 3652 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-03-03 17:36:48.030 INFO 3652 --- [jo-jmh-worker-1] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 Redis repository interfaces.
2020-03-03 17:36:48.939 INFO 3652 --- [jo-jmh-worker-1] o.s.boot.SpringApplication : Started application in 1.71 seconds (JVM running for 2.398)
2020-03-03 17:36:49.234 INFO 3652 --- [jo-jmh-worker-1] io.lettuce.core.EpollProvider : Starting without optional epoll library
2020-03-03 17:36:49.236 INFO 3652 --- [jo-jmh-worker-1] io.lettuce.core.KqueueProvider : Starting without optional kqueue library
8.136 ms/op
Iteration 1: 7.129 ms/op
Iteration 2: 7.089 ms/op
Iteration 3: 7.080 ms/op
Iteration 4: 7.048 ms/op
Iteration 5: 7.096 ms/op
Iteration 6: 7.168 ms/op
Iteration 7: 7.784 ms/op
Iteration 8: 7.042 ms/op
Iteration 9: 7.051 ms/op
Iteration 10: 7.046 ms/op
Iteration 11: 7.054 ms/op
Iteration 12: 7.041 ms/op
Iteration 13: 7.051 ms/op
Iteration 14: 7.091 ms/op
Iteration 15: 7.172 ms/op
Iteration 16: 7.318 ms/op
Iteration 17: 7.065 ms/op
Iteration 18: 7.190 ms/op
Iteration 19: 7.173 ms/op
Iteration 20: 7.192 ms/op
Result "com.springboot.AppTest.testGetPojo":
7.250 ±(99.9%) 0.336 ms/op [Average]
**(min, avg, max)** **= (7.019, 7.250, 10.824), stdev = 0.597
CI (99.9%): [6.914, 7.586****] (assumes normal distribution)**
# Run complete. Total time: 00:07:06
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
AppTest.testGetPojo avgt 40 7.250 ± 0.336 ms/op
Process finished with exit code 0
40 次耗时 7.25 秒,单次运行最小 7.019 秒,平均 7.250 秒, 最大 (最差) 10.824 毫秒
转载自:https://blog.csdn.net/lxbjkben/article/details/79410740 https://blog.csdn.net/peng_0129/article/details/100134320 https://juejin.im/post/5ddf7e006fb9a071b86cc422
作者:你不知道的浪漫
来源链接:
https://www.cnblogs.com/passedbylove/p/12398230.html