package com.xdclass.couponapp;
import com.xdclass.couponapp.service.CouponService;
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.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@State(Scope.Thread)
public class JMHSpringBootTest {
private ConfigurableApplicationContext context;
private CouponService couponService;
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder().include(JMHSpringBootTest.class.getName()+".*")
.warmupIterations(2).measurementIterations(2).forks(1).build();
new Runner(options).run();
}
/**
* setup初始化容器的时候只执行一次
*/
@Setup(Level.Tria
Springboot整合JMH基准测试
最新推荐文章于 2026-02-14 07:14:35 发布
本文介绍了如何在Springboot应用中整合JMH(Java Microbenchmark Harness)进行基准测试,通过一个具体的`JMHSpringBootTest.test`基准测试,展示了在测试环境中实现了每秒335.917次操作的性能。


1001

被折叠的 条评论
为什么被折叠?



