SpringBoot集成JMH进行基准测试2

接上篇:SpringBoot集成JMH进行基准测试

本地环境: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:developjavajdk1.8.0_181injava.exe "-javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2018.3.4libidea_rt.jar=58738:D:Program FilesJetBrainsIntelliJ IDEA 2018.3.4in" -Dfile.encoding=UTF-8 -classpath D:developjavajdk1.8.0_181jrelibcharsets.jar;D:developjavajdk1.8.0_181jrelibdeploy.jar;D:developjavajdk1.8.0_181jrelibextaccess-bridge-64.jar;D:developjavajdk1.8.0_181jrelibextcldrdata.jar;D:developjavajdk1.8.0_181jrelibextdnsns.jar;D:developjavajdk1.8.0_181jrelibextjaccess.jar;D:developjavajdk1.8.0_181jrelibextjfxrt.jar;D:developjavajdk1.8.0_181jrelibextlocaledata.jar;D:developjavajdk1.8.0_181jrelibext
ashorn.jar;D:developjavajdk1.8.0_181jrelibextsunec.jar;D:developjavajdk1.8.0_181jrelibextsunjce_provider.jar;D:developjavajdk1.8.0_181jrelibextsunmscapi.jar;D:developjavajdk1.8.0_181jrelibextsunpkcs11.jar;D:developjavajdk1.8.0_181jrelibextzipfs.jar;D:developjavajdk1.8.0_181jrelibjavaws.jar;D:developjavajdk1.8.0_181jrelibjce.jar;D:developjavajdk1.8.0_181jrelibjfr.jar;D:developjavajdk1.8.0_181jrelibjfxswt.jar;D:developjavajdk1.8.0_181jrelibjsse.jar;D:developjavajdk1.8.0_181jrelibmanagement-agent.jar;D:developjavajdk1.8.0_181jrelibplugin.jar;D:developjavajdk1.8.0_181jrelib
esources.jar;D:developjavajdk1.8.0_181jrelib
t.jar;E:projectjavaspringBootJmh	arget	est-classes;E:projectjavaspringBootJmh	argetclasses;D:developapache-maven-3.5.4
epoorgapachecommonscommons-pool22.5.0commons-pool2-2.5.0.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-starter-cache2.2.4.RELEASEspring-boot-starter-cache-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-starter2.2.4.RELEASEspring-boot-starter-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot2.2.4.RELEASEspring-boot-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-autoconfigure2.2.4.RELEASEspring-boot-autoconfigure-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-starter-logging2.2.4.RELEASEspring-boot-starter-logging-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epochqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;D:developapache-maven-3.5.4
epochqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;D:developapache-maven-3.5.4
epoorgapachelogginglog4jlog4j-to-slf4j2.12.1log4j-to-slf4j-2.12.1.jar;D:developapache-maven-3.5.4
epoorgapachelogginglog4jlog4j-api2.12.1log4j-api-2.12.1.jar;D:developapache-maven-3.5.4
epoorgslf4jjul-to-slf4j1.7.30jul-to-slf4j-1.7.30.jar;D:developapache-maven-3.5.4
epojakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;D:developapache-maven-3.5.4
epoorgyamlsnakeyaml1.25snakeyaml-1.25.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-context-support5.2.3.RELEASEspring-context-support-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-beans5.2.3.RELEASEspring-beans-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-context5.2.3.RELEASEspring-context-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-expression5.2.3.RELEASEspring-expression-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-starter-data-redis2.2.4.RELEASEspring-boot-starter-data-redis-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkdataspring-data-redis2.2.4.RELEASEspring-data-redis-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkdataspring-data-keyvalue2.2.4.RELEASEspring-data-keyvalue-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkdataspring-data-commons2.2.4.RELEASEspring-data-commons-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-tx5.2.3.RELEASEspring-tx-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-oxm5.2.3.RELEASEspring-oxm-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-aop5.2.3.RELEASEspring-aop-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;D:developapache-maven-3.5.4
epoiolettucelettuce-core5.2.1.RELEASElettuce-core-5.2.1.RELEASE.jar;D:developapache-maven-3.5.4
epoio
etty
etty-common4.1.45.Final
etty-common-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoio
etty
etty-handler4.1.45.Final
etty-handler-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoio
etty
etty-buffer4.1.45.Final
etty-buffer-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoio
etty
etty-codec4.1.45.Final
etty-codec-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoio
etty
etty-transport4.1.45.Final
etty-transport-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoio
etty
etty-resolver4.1.45.Final
etty-resolver-4.1.45.Final.jar;D:developapache-maven-3.5.4
epoioprojectreactor
eactor-core3.3.2.RELEASE
eactor-core-3.3.2.RELEASE.jar;D:developapache-maven-3.5.4
epoorg
eactivestreams
eactive-streams1.0.3
eactive-streams-1.0.3.jar;D:developapache-maven-3.5.4
epocomdyuprojectprotostuffprotostuff-runtime1.1.3protostuff-runtime-1.1.3.jar;D:developapache-maven-3.5.4
epocomdyuprojectprotostuffprotostuff-collectionschema1.1.3protostuff-collectionschema-1.1.3.jar;D:developapache-maven-3.5.4
epocomdyuprojectprotostuffprotostuff-api1.0.8protostuff-api-1.0.8.jar;D:developapache-maven-3.5.4
epocomdyuprojectprotostuffprotostuff-core1.0.8protostuff-core-1.0.8.jar;D:developapache-maven-3.5.4
epoorgprojectlomboklombok1.18.10lombok-1.18.10.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-starter-test2.2.4.RELEASEspring-boot-starter-test-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-test2.2.4.RELEASEspring-boot-test-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkootspring-boot-test-autoconfigure2.2.4.RELEASEspring-boot-test-autoconfigure-2.2.4.RELEASE.jar;D:developapache-maven-3.5.4
epocomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;D:developapache-maven-3.5.4
epo
etminidevjson-smart2.3json-smart-2.3.jar;D:developapache-maven-3.5.4
epo
etminidevaccessors-smart1.2accessors-smart-1.2.jar;D:developapache-maven-3.5.4
epoorgow2asmasm5.0.4asm-5.0.4.jar;D:developapache-maven-3.5.4
epojakartaxmlindjakarta.xml.bind-api2.3.2jakarta.xml.bind-api-2.3.2.jar;D:developapache-maven-3.5.4
epojakartaactivationjakarta.activation-api1.2.1jakarta.activation-api-1.2.1.jar;D:developapache-maven-3.5.4
epoorgjunitjupiterjunit-jupiter5.5.2junit-jupiter-5.5.2.jar;D:developapache-maven-3.5.4
epoorgjunitjupiterjunit-jupiter-api5.5.2junit-jupiter-api-5.5.2.jar;D:developapache-maven-3.5.4
epoorgapiguardianapiguardian-api1.1.0apiguardian-api-1.1.0.jar;D:developapache-maven-3.5.4
epoorgopentest4jopentest4j1.2.0opentest4j-1.2.0.jar;D:developapache-maven-3.5.4
epoorgjunitplatformjunit-platform-commons1.5.2junit-platform-commons-1.5.2.jar;D:developapache-maven-3.5.4
epoorgjunitjupiterjunit-jupiter-params5.5.2junit-jupiter-params-5.5.2.jar;D:developapache-maven-3.5.4
epoorgjunitjupiterjunit-jupiter-engine5.5.2junit-jupiter-engine-5.5.2.jar;D:developapache-maven-3.5.4
epoorgjunitplatformjunit-platform-engine1.5.2junit-platform-engine-1.5.2.jar;D:developapache-maven-3.5.4
epoorgmockitomockito-junit-jupiter3.1.0mockito-junit-jupiter-3.1.0.jar;D:developapache-maven-3.5.4
epoorgassertjassertj-core3.13.2assertj-core-3.13.2.jar;D:developapache-maven-3.5.4
epoorghamcresthamcrest2.1hamcrest-2.1.jar;D:developapache-maven-3.5.4
epoorgmockitomockito-core3.1.0mockito-core-3.1.0.jar;D:developapache-maven-3.5.4
epo
etytebuddybyte-buddy1.10.6byte-buddy-1.10.6.jar;D:developapache-maven-3.5.4
epo
etytebuddybyte-buddy-agent1.10.6byte-buddy-agent-1.10.6.jar;D:developapache-maven-3.5.4
epoorgobjenesisobjenesis2.6objenesis-2.6.jar;D:developapache-maven-3.5.4
epoorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;D:developapache-maven-3.5.4
epocomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-core5.2.3.RELEASEspring-core-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-jcl5.2.3.RELEASEspring-jcl-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgspringframeworkspring-test5.2.3.RELEASEspring-test-5.2.3.RELEASE.jar;D:developapache-maven-3.5.4
epoorgxmlunitxmlunit-core2.6.3xmlunit-core-2.6.3.jar;D:developapache-maven-3.5.4
epocomgoogleguavaguava20.0guava-20.0.jar;D:developapache-maven-3.5.4
epocomgooglecodegsongson2.8.4gson-2.8.4.jar;D:developapache-maven-3.5.4
epoorgmodelmappermodelmapper.7.7modelmapper-0.7.7.jar;D:developapache-maven-3.5.4
epoorgopenjdkjmhjmh-core1.21jmh-core-1.21.jar;D:developapache-maven-3.5.4
epo
etsfjopt-simplejopt-simple4.6jopt-simple-4.6.jar;D:developapache-maven-3.5.4
epoorgapachecommonscommons-math33.2commons-math3-3.2.jar;D:developapache-maven-3.5.4
epoorgopenjdkjmhjmh-generator-annprocess1.21jmh-generator-annprocess-1.21.jar;D:developapache-maven-3.5.4
epocomfasterxmljacksoncorejackson-annotations2.10.2jackson-annotations-2.10.2.jar;D:developapache-maven-3.5.4
epocomfasterxmljacksoncorejackson-databind2.10.2jackson-databind-2.10.2.jar;D:developapache-maven-3.5.4
epocomfasterxmljacksoncorejackson-core2.10.2jackson-core-2.10.2.jar;D:developapache-maven-3.5.4
epocomfasterxmljacksondatatypejackson-datatype-jsr3102.10.2jackson-datatype-jsr310-2.10.2.jar;D:developapache-maven-3.5.4
epocommons-beanutilscommons-beanutils1.9.3commons-beanutils-1.9.3.jar;D:developapache-maven-3.5.4
epocommons-loggingcommons-logging1.2commons-logging-1.2.jar;D:developapache-maven-3.5.4
epocommons-collectionscommons-collections3.2.2commons-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:developjavajdk1.8.0_181jreinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2018.3.4libidea_rt.jar=58738:D:Program FilesJetBrainsIntelliJ IDEA 2018.3.4in -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:projectjavaspringBootJmh)
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:projectjavaspringBootJmh)
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