zoukankan      html  css  js  c++  java
  • SpringBoot集成JMH

    第一步:添加依赖:

    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-core</artifactId>
    <version>1.19</version>
    </dependency>
    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-generator-annprocess</artifactId>
    <version>1.19</version>
    <scope>provided</scope>
    </dependency>

    第二步:创建类:
    /**
     * @desc:
     * @author: 毛会懂
     * @create: 2021-11-16 13:32:00
     **/
    @BenchmarkMode(Mode.AverageTime)
    @OutputTimeUnit(TimeUnit.MILLISECONDS)
    @Warmup(iterations = 5,time = 1,timeUnit = TimeUnit.SECONDS)
    @Measurement(iterations = 5,time = 1,timeUnit = TimeUnit.SECONDS)
    @Fork(1)
    @State(Scope.Benchmark)
    public class JMHFirstBenchmark {
    
        private BarrageService barrageService;
    
        @Setup(Level.Trial)
        public void setUp(){
            // 启动应用程序
            ConfigurableApplicationContext run = SpringApplication.run(xxxxApplicationBootstrap.class);
            // 从spring中拿Bean
            barrageService = run.getBean(BarrageService.class);
        }
    
        @Benchmark
        public void barrage(Blackhole bh1) throws InterruptedException {
            BarrageDTO barrage = new BarrageDTO();
            barrage.setActivityId(5368);
            ApiResult activityBarrages = barrageService.getActivityBarrages(barrage);
            bh1.consume(activityBarrages); // 防止jit陷阱
        }
    
        public static void main(String[] args) throws RunnerException {
            Options build = new OptionsBuilder().include(JMHFirstBenchmark.class.getSimpleName())
                    .build();
            new Runner(build).run();
        }
    }

    问题:jmh执行完, 应用还在启动中,会报错,但不影响jmh的使用。
  • 相关阅读:
    des和Rijndael加密
    信息熵
    逻辑回归简单多变不易把握、特征离散化原因、最大熵模型
    特征选择
    数据清洗
    海塞矩阵、黄金分割、牛顿法、下降迭代法
    BP算法推导python实现
    分布函数,概率,离散,连续
    损失函数coding
    leetcode中二分查找的具体应用
  • 原文地址:https://www.cnblogs.com/maohuidong/p/15566091.html
Copyright © 2011-2022 走看看