大家好,又见面了,我是你们的朋友全栈君。
JMH简介
官网:http://openjdk.java.net/projects/code-tools/jmh/
简介:JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targetting the JVM,由简介可知,JMH不止能对Java语言做基准测试,还能对运行在JVM上的其他语言做基准测试。而且可以分析到纳秒级别。
JMH比较典型的应用场景有:
- 想准确的知道某个方法需要执行多长时间,以及执行时间和输入之间的相关性;
- 对比接口不同实现在给定条件下的吞吐量,找到最优实现
- 查看多少百分比的请求在多长时间内完成
官方是推荐我们单独建立一个maven工程来进行测试, 但是我们的就做一些方法的基准测试, 没有必要还单独去建立一个maven工程.
如果你当前的jdk版本小于12, 需要添加maven依赖, 如果版本大于等于12就不需要了, 已经包含在里面了.
代码语言:javascript复制 </dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.23</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.23</version>
</dependency>
现在使用JMH 有两种方式, 一种是注解, 一种是代码配置的方式,
这里我们就说代码配置的方式, 因为这个东西用的不多, 记不住那么多的注解.
上代码:
代码语言:javascript复制package other;
import org.openjdk.jmh.annotations.Benchmark;
/**
* string 链接的性能测试
*/
public class StringConnectBenchmark {
/**
* 字符串拼接之 StringBuilder 基准测试
*/
@Benchmark
public void testStringBuilder() {
print(new StringBuilder().append(1).append(2).append(3).toString());
}
/**
* 字符串拼接之直接相加基准测试
*/
@Benchmark
public void testStringAdd() {
print(new String() 1 2 3);
}
/**
* 字符串拼接之String Concat基准测试
*/
@Benchmark
public void testStringConcat() {
print(new String().concat("1").concat("2").concat("3"));
}
/**
* 字符串拼接之 StringBuffer 基准测试
*/
@Benchmark
public void testStringBuffer() {
print(new StringBuffer().append(1).append(2).append(3).toString());
}
/**
* 字符串拼接之 StringFormat 基准测试
*/
@Benchmark
public void testStringFormat(){
print(String.format("%s%s%s", 1, 2, 3));
}
public void print(String str) {
// System.out.println(str);
}
}
代码语言:javascript复制import org.openjdk.jmh.annotations.Mode;
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.openjdk.jmh.runner.options.TimeValue;
import other.StringConnectBenchmark;
/**
* @author onyx
* @date 2020年6月3日14:53:09
*/
public class StringBuilderTest {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
/**
*导入要测试的类
*/
.include(StringConnectBenchmark.class.getSimpleName())
/**
* 要排除的, 其实很简单, 方法上不加@Benchmark 注解就好了
*/
//.exclude("")
/**
* 预热的迭代次数 3轮
*/
.warmupIterations(3)
/**
* 预热模式:INDI,BULK,BULK_INDI
*/
//.warmupForks()
/**
* 预热时间 10 s
*/
.warmupTime(TimeValue.seconds(1))
/**
* 测试的迭代次数 3轮
*/
.measurementIterations(3)
/**
* 测试模式: Throughput(吞吐量), AverageTime(平均时间),
* SampleTime(在测试中,随机进行采样执行的时间),SingleShotTime(在每次执行中计算耗时),All
*
* 耗时非常短的看 吞吐量 . 耗时有明显不同的可以看时间.
*/
.mode(Mode.Throughput)
/**
* 子进程的个数,用于测试,这里是3
*/
.forks(3)
/**
* 得到最终的配置了参数的配置
*/
.build();
new Runner(opt).run();
}
}
记住了, 这两个java文件不能再同一个包里面…. 否则运行报错. 亲测.
代码解释:
在 Main 方法中,通过 org.openjdk.jmh.runner.Runner 类去运行 org.openjdk.jmh.runner.options.Options 实例即可。这里的重点在于 Options 对象的构建。官方提供了一个OptionsBuilder对象去构建。这个 Builder对象是流式的。它的常用方法及对应的注解形式如下:
方法名 | 参数 | 作用 | 对应注解 |
---|---|---|---|
include | 要运行基准测试类的简单名称 eg. StringConnectBenchmark | 指定要运行的基准测试类 | – |
exclude | 不要运行基准测试类的简单名称 eg. StringConnectBenchmark | 指定不要运行的基准测试类 | – |
warmupIterations | 预热的迭代次数 | 指定预热的迭代次数 | @Warmup |
warmupBatchSize | 预热批量的大小 | 指定预热批量的大小 | @Warmup |
warmupForks | 预热模式:INDI,BULK,BULK_INDI | 指定预热模式 | @Warmup |
warmupMode | 预热的模式 | 指定预热的模式 | @Warmup |
warmupTime | 预热的时间 | 指定预热的时间 | @Warmup |
measurementIterations | 测试的迭代次数 | 指定测试的迭代次数 | @Measurement |
measurementBatchSize | 测试批量的大小 | 指定测试批量的大小 | @Measurement |
measurementTime | 测试的时间 | 指定测试的时间 | @Measurement |
mode | 测试模式: Throughput(吞吐量), AverageTime(平均时间),SampleTime(在测试中,随机进行采样执行的时间),SingleShotTime(在每次执行中计算耗时),All | 指定测试的模式 | @BenchmarkMode |
这里你们就知道了, 其实写配置 和 写注解是一样的, 没啥大的区别. 下面是运行结果:
代码语言:javascript复制/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释
* "C:Program FilesJavajdk1.8.0_172binjava" "-javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_172jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_172jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_172jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_172jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_172jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_172jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_172jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_172jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_172jrelibextnashorn.jar;C:Program FilesJavajdk1.8.0_172jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_172jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_172jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_172jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_172jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_172jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_172jrelibjce.jar;C:Program FilesJavajdk1.8.0_172jrelibjfr.jar;C:Program FilesJavajdk1.8.0_172jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_172jrelibjsse.jar;C:Program FilesJavajdk1.8.0_172jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_172jrelibplugin.jar;C:Program FilesJavajdk1.8.0_172jrelibresources.jar;C:Program FilesJavajdk1.8.0_172jrelibrt.jar;D:workspace2020goodstargetclasses;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-netflix-eureka-client2.0.2.RELEASEspring-cloud-starter-netflix-eureka-client-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter2.0.2.RELEASEspring-cloud-starter-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-context2.0.2.RELEASEspring-cloud-context-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworksecurityspring-security-rsa1.0.7.RELEASEspring-security-rsa-1.0.7.RELEASE.jar;D:softmavenstorageorgbouncycastlebcpkix-jdk15on1.59bcpkix-jdk15on-1.59.jar;D:softmavenstorageorgbouncycastlebcprov-jdk15on1.59bcprov-jdk15on-1.59.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-netflix-core2.0.2.RELEASEspring-cloud-netflix-core-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-autoconfigure2.0.6.RELEASEspring-boot-autoconfigure-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-netflix-eureka-client2.0.2.RELEASEspring-cloud-netflix-eureka-client-2.0.2.RELEASE.jar;D:softmavenstoragecomnetflixeurekaeureka-client1.9.3eureka-client-1.9.3.jar;D:softmavenstorageorgcodehausjettisonjettison1.2jettison-1.2.jar;D:softmavenstoragestaxstax-api1.0.1stax-api-1.0.1.jar;D:softmavenstoragecomnetflixnetflix-commonsnetflix-eventbus .3.0netflix-eventbus-0.3.0.jar;D:softmavenstoragecomnetflixnetflix-commonsnetflix-infix .3.0netflix-infix-0.3.0.jar;D:softmavenstoragecommons-jxpathcommons-jxpath1.3commons-jxpath-1.3.jar;D:softmavenstoragejoda-timejoda-time2.9.9joda-time-2.9.9.jar;D:softmavenstorageorgantlrantlr-runtime3.4antlr-runtime-3.4.jar;D:softmavenstorageorgantlrstringtemplate3.2.1stringtemplate-3.2.1.jar;D:softmavenstorageantlrantlr2.7.7antlr-2.7.7.jar;D:softmavenstoragecomgooglecodegsongson2.8.5gson-2.8.5.jar;D:softmavenstorageorgapachecommonscommons-math2.2commons-math-2.2.jar;D:softmavenstoragecomnetflixarchaiusarchaius-core .7.6archaius-core-0.7.6.jar;D:softmavenstoragecomgoogleguavaguava20.0guava-20.0.jar;D:softmavenstoragejavaxwsrsjsr311-api1.1.1jsr311-api-1.1.1.jar;D:softmavenstoragecomnetflixservoservo-core .12.21servo-core-0.12.21.jar;D:softmavenstoragecomsunjerseyjersey-core1.19.1jersey-core-1.19.1.jar;D:softmavenstoragecomsunjerseyjersey-client1.19.1jersey-client-1.19.1.jar;D:softmavenstoragecomsunjerseycontribsjersey-apache-client41.19.1jersey-apache-client4-1.19.1.jar;D:softmavenstorageorgapachehttpcomponentshttpclient4.5.6httpclient-4.5.6.jar;D:softmavenstorageorgapachehttpcomponentshttpcore4.4.10httpcore-4.4.10.jar;D:softmavenstoragecomgoogleinjectguice3.0guice-3.0.jar;D:softmavenstoragejavaxinjectjavax.inject1javax.inject-1.jar;D:softmavenstorageaopallianceaopalliance1.0aopalliance-1.0.jar;D:softmavenstoragecomgithubvlsicompactmapcompactmap1.2.1compactmap-1.2.1.jar;D:softmavenstoragecomgithubandrewomadexxdexx-collections .2dexx-collections-0.2.jar;D:softmavenstoragecomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;D:softmavenstoragecomfasterxmljacksoncorejackson-core2.9.7jackson-core-2.9.7.jar;D:softmavenstoragecomfasterxmljacksoncorejackson-databind2.9.7jackson-databind-2.9.7.jar;D:softmavenstoragecomnetflixeurekaeureka-core1.9.3eureka-core-1.9.3.jar;D:softmavenstorageorgcodehauswoodstoxwoodstox-core-asl4.4.1woodstox-core-asl-4.4.1.jar;D:softmavenstoragejavaxxmlstreamstax-api1.0-2stax-api-1.0-2.jar;D:softmavenstorageorgcodehauswoodstoxstax2-api3.1.4stax2-api-3.1.4.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-netflix-archaius2.0.2.RELEASEspring-cloud-starter-netflix-archaius-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-netflix-ribbon2.0.2.RELEASEspring-cloud-netflix-ribbon-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-netflix-archaius2.0.2.RELEASEspring-cloud-netflix-archaius-2.0.2.RELEASE.jar;D:softmavenstoragecommons-configurationcommons-configuration1.8commons-configuration-1.8.jar;D:softmavenstoragecommons-langcommons-lang2.6commons-lang-2.6.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-netflix-ribbon2.0.2.RELEASEspring-cloud-starter-netflix-ribbon-2.0.2.RELEASE.jar;D:softmavenstoragecomnetflixribbonribbon2.2.5ribbon-2.2.5.jar;D:softmavenstoragecomnetflixribbonribbon-transport2.2.5ribbon-transport-2.2.5.jar;D:softmavenstorageioreactivexrxnetty-contexts .4.9rxnetty-contexts-0.4.9.jar;D:softmavenstorageioreactivexrxnetty-servo .4.9rxnetty-servo-0.4.9.jar;D:softmavenstorageioreactivexrxnetty .4.9rxnetty-0.4.9.jar;D:softmavenstoragecomnetflixribbonribbon-core2.2.5ribbon-core-2.2.5.jar;D:softmavenstoragecomnetflixribbonribbon-httpclient2.2.5ribbon-httpclient-2.2.5.jar;D:softmavenstoragecommons-collectionscommons-collections3.2.2commons-collections-3.2.2.jar;D:softmavenstoragecomnetflixnetflix-commonsnetflix-commons-util .3.0netflix-commons-util-0.3.0.jar;D:softmavenstoragecomnetflixribbonribbon-loadbalancer2.2.5ribbon-loadbalancer-2.2.5.jar;D:softmavenstoragecomnetflixnetflix-commonsnetflix-statistics .1.1netflix-statistics-0.1.1.jar;D:softmavenstorageioreactivexrxjava1.3.8rxjava-1.3.8.jar;D:softmavenstoragecomnetflixribbonribbon-eureka2.2.5ribbon-eureka-2.2.5.jar;D:softmavenstorageorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;D:softmavenstoragecomthoughtworksxstreamxstream1.4.10xstream-1.4.10.jar;D:softmavenstoragexmlpullxmlpull1.1.3.1xmlpull-1.1.3.1.jar;D:softmavenstoragexpp3xpp3_min1.1.4cxpp3_min-1.1.4c.jar;D:softmavenstoragecomalibabacloudspring-cloud-starter-alibaba-sentinel2.0.0.RELEASEspring-cloud-starter-alibaba-sentinel-2.0.0.RELEASE.jar;D:softmavenstoragecomalibabacloudspring-cloud-alibaba-sentinel2.0.0.RELEASEspring-cloud-alibaba-sentinel-2.0.0.RELEASE.jar;D:softmavenstoragecomalibabacspsentinel-annotation-aspectj1.6.3sentinel-annotation-aspectj-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-core1.6.3sentinel-core-1.6.3.jar;D:softmavenstorageorgaspectjaspectjrt1.8.13aspectjrt-1.8.13.jar;D:softmavenstoragecomalibabacspsentinel-web-servlet1.6.3sentinel-web-servlet-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-spring-webflux-adapter1.6.3sentinel-spring-webflux-adapter-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-reactor-adapter1.6.3sentinel-reactor-adapter-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-parameter-flow-control1.6.3sentinel-parameter-flow-control-1.6.3.jar;D:softmavenstoragecomgooglecodeconcurrentlinkedhashmapconcurrentlinkedhashmap-lru1.4.2concurrentlinkedhashmap-lru-1.4.2.jar;D:softmavenstoragecomalibabacspsentinel-cluster-server-default1.6.3sentinel-cluster-server-default-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-cluster-common-default1.6.3sentinel-cluster-common-default-1.6.3.jar;D:softmavenstorageionettynetty-handler4.1.29.Finalnetty-handler-4.1.29.Final.jar;D:softmavenstorageionettynetty-buffer4.1.29.Finalnetty-buffer-4.1.29.Final.jar;D:softmavenstorageionettynetty-common4.1.29.Finalnetty-common-4.1.29.Final.jar;D:softmavenstorageionettynetty-transport4.1.29.Finalnetty-transport-4.1.29.Final.jar;D:softmavenstorageionettynetty-resolver4.1.29.Finalnetty-resolver-4.1.29.Final.jar;D:softmavenstorageionettynetty-codec4.1.29.Finalnetty-codec-4.1.29.Final.jar;D:softmavenstoragecomalibabacspsentinel-cluster-client-default1.6.3sentinel-cluster-client-default-1.6.3.jar;D:softmavenstoragecomalibabacloudspring-cloud-alibaba-sentinel-datasource2.0.0.RELEASEspring-cloud-alibaba-sentinel-datasource-2.0.0.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter2.0.6.RELEASEspring-boot-starter-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot2.0.6.RELEASEspring-boot-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-logging2.0.6.RELEASEspring-boot-starter-logging-2.0.6.RELEASE.jar;D:softmavenstoragechqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;D:softmavenstoragechqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;D:softmavenstorageorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;D:softmavenstorageorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;D:softmavenstorageorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;D:softmavenstoragejavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;D:softmavenstorageorgyamlsnakeyaml1.19snakeyaml-1.19.jar;D:softmavenstorageorgspringframeworkspring-core5.0.10.RELEASEspring-core-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-jcl5.0.10.RELEASEspring-jcl-5.0.10.RELEASE.jar;D:softmavenstoragecomcurefunapplicationapplication-pom1.0.0application-pom-1.0.0.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-zipkin2.0.2.RELEASEspring-cloud-starter-zipkin-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-sleuth2.0.2.RELEASEspring-cloud-starter-sleuth-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-sleuth-core2.0.2.RELEASEspring-cloud-sleuth-core-2.0.2.RELEASE.jar;D:softmavenstorageiozipkinbravebrave5.4.3brave-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-context-log4j25.4.3brave-context-log4j2-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-spring-web5.4.3brave-instrumentation-spring-web-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-http5.4.3brave-instrumentation-http-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-spring-rabbit5.4.3brave-instrumentation-spring-rabbit-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-kafka-clients5.4.3brave-instrumentation-kafka-clients-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-httpclient5.4.3brave-instrumentation-httpclient-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-httpasyncclient5.4.3brave-instrumentation-httpasyncclient-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-spring-webmvc5.4.3brave-instrumentation-spring-webmvc-5.4.3.jar;D:softmavenstorageiozipkinbravebrave-instrumentation-servlet5.4.3brave-instrumentation-servlet-5.4.3.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-sleuth-zipkin2.0.2.RELEASEspring-cloud-sleuth-zipkin-2.0.2.RELEASE.jar;D:softmavenstorageiozipkinzipkin2zipkin2.11.7zipkin-2.11.7.jar;D:softmavenstorageiozipkinreporter2zipkin-reporter2.7.10zipkin-reporter-2.7.10.jar;D:softmavenstorageiozipkinreporter2zipkin-sender-kafka112.7.10zipkin-sender-kafka11-2.7.10.jar;D:softmavenstorageiozipkinreporter2zipkin-sender-amqp-client2.7.10zipkin-sender-amqp-client-2.7.10.jar;D:softmavenstoragecomalibabacspsentinel-transport-simple-http1.6.3sentinel-transport-simple-http-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-transport-common1.6.3sentinel-transport-common-1.6.3.jar;D:softmavenstoragecomalibabacspsentinel-datasource-extension1.6.3sentinel-datasource-extension-1.6.3.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-actuator2.0.6.RELEASEspring-boot-starter-actuator-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-actuator-autoconfigure2.0.6.RELEASEspring-boot-actuator-autoconfigure-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-actuator2.0.6.RELEASEspring-boot-actuator-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-context5.0.10.RELEASEspring-context-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-expression5.0.10.RELEASEspring-expression-5.0.10.RELEASE.jar;D:softmavenstoragecomfasterxmljacksondatatypejackson-datatype-jsr3102.9.7jackson-datatype-jsr310-2.9.7.jar;D:softmavenstorageiomicrometermicrometer-core1.0.7micrometer-core-1.0.7.jar;D:softmavenstorageorghdrhistogramHdrHistogram2.1.10HdrHistogram-2.1.10.jar;D:softmavenstorageorglatencyutilsLatencyUtils2.0.3LatencyUtils-2.0.3.jar;D:softmavenstoragecomcurefuncorecurefun-core1.0.46curefun-core-1.0.46.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-web2.0.6.RELEASEspring-boot-starter-web-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-json2.0.6.RELEASEspring-boot-starter-json-2.0.6.RELEASE.jar;D:softmavenstoragecomfasterxmljacksondatatypejackson-datatype-jdk82.9.7jackson-datatype-jdk8-2.9.7.jar;D:softmavenstoragecomfasterxmljacksonmodulejackson-module-parameter-names2.9.7jackson-module-parameter-names-2.9.7.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-tomcat2.0.6.RELEASEspring-boot-starter-tomcat-2.0.6.RELEASE.jar;D:softmavenstorageorgapachetomcatembedtomcat-embed-core8.5.34tomcat-embed-core-8.5.34.jar;D:softmavenstorageorgapachetomcatembedtomcat-embed-el8.5.34tomcat-embed-el-8.5.34.jar;D:softmavenstorageorgapachetomcatembedtomcat-embed-websocket8.5.34tomcat-embed-websocket-8.5.34.jar;D:softmavenstorageorghibernatevalidatorhibernate-validator6.0.13.Finalhibernate-validator-6.0.13.Final.jar;D:softmavenstoragejavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;D:softmavenstorageorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;D:softmavenstoragecomfasterxmlclassmate1.3.4classmate-1.3.4.jar;D:softmavenstorageorgspringframeworkspring-webmvc5.0.10.RELEASEspring-webmvc-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-aop2.0.6.RELEASEspring-boot-starter-aop-2.0.6.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-aop5.0.10.RELEASEspring-aop-5.0.10.RELEASE.jar;D:softmavenstorageorgaspectjaspectjweaver1.8.13aspectjweaver-1.8.13.jar;D:softmavenstoragecombaomidoumybatis-plus-boot-starter3.0.7mybatis-plus-boot-starter-3.0.7.jar;D:softmavenstoragecombaomidoumybatis-plus3.0.7mybatis-plus-3.0.7.jar;D:softmavenstoragecombaomidoumybatis-plus-extension3.0.7mybatis-plus-extension-3.0.7.jar;D:softmavenstoragecombaomidoumybatis-plus-core3.0.7mybatis-plus-core-3.0.7.jar;D:softmavenstoragecombaomidoumybatis-plus-annotation3.0.7mybatis-plus-annotation-3.0.7.jar;D:softmavenstoragecomgithubjsqlparserjsqlparser1.3jsqlparser-1.3.jar;D:softmavenstorageorgmybatismybatis-spring1.3.2mybatis-spring-1.3.2.jar;D:softmavenstorageorgmybatismybatis3.4.6mybatis-3.4.6.jar;D:softmavenstorageorgspringframeworkbootspring-boot-starter-jdbc2.0.6.RELEASEspring-boot-starter-jdbc-2.0.6.RELEASE.jar;D:softmavenstoragecomzaxxerHikariCP2.7.9HikariCP-2.7.9.jar;D:softmavenstorageorgspringframeworkspring-jdbc5.0.10.RELEASEspring-jdbc-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-tx5.0.10.RELEASEspring-tx-5.0.10.RELEASE.jar;D:softmavenstoragecomalibabadruid-spring-boot-starter1.1.10druid-spring-boot-starter-1.1.10.jar;D:softmavenstoragecomalibabadruid1.1.10druid-1.1.10.jar;D:softmavenstorageorgprojectlomboklombok1.16.22lombok-1.16.22.jar;D:softmavenstoragecomalibabafastjson1.2.47fastjson-1.2.47.jar;D:softmavenstoragemysqlmysql-connector-java5.1.46mysql-connector-java-5.1.46.jar;D:softmavenstoragecomsquareupokhttp3okhttp3.8.1okhttp-3.8.1.jar;D:softmavenstoragecomsquareupokiookio1.13.0okio-1.13.0.jar;D:softmavenstoragecomgooglezxingcore3.2.1core-3.2.1.jar;D:softmavenstoragecomgooglezxingjavase3.2.1javase-3.2.1.jar;D:softmavenstoragecombeustjcommander1.48jcommander-1.48.jar;D:softmavenstoragearcomhjgpngj2.1.0pngj-2.1.0.jar;D:softmavenstorageorgapachepoipoi3.14poi-3.14.jar;D:softmavenstoragecommons-codeccommons-codec1.11commons-codec-1.11.jar;D:softmavenstorageorgapachepoipoi-ooxml3.14poi-ooxml-3.14.jar;D:softmavenstorageorgapachepoipoi-ooxml-schemas3.14poi-ooxml-schemas-3.14.jar;D:softmavenstorageorgapachexmlbeansxmlbeans2.6.0xmlbeans-2.6.0.jar;D:softmavenstoragecomgithubvirtualdcurvesapi1.03curvesapi-1.03.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-starter-openfeign2.0.2.RELEASEspring-cloud-starter-openfeign-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-openfeign-core2.0.2.RELEASEspring-cloud-openfeign-core-2.0.2.RELEASE.jar;D:softmavenstorageiogithubopenfeignformfeign-form-spring3.3.0feign-form-spring-3.3.0.jar;D:softmavenstorageiogithubopenfeignformfeign-form3.3.0feign-form-3.3.0.jar;D:softmavenstoragecomgooglecodefindbugsannotations3.0.1annotations-3.0.1.jar;D:softmavenstoragenetjcipjcip-annotations1.0jcip-annotations-1.0.jar;D:softmavenstoragecomgooglecodefindbugsjsr3053.0.2jsr305-3.0.2.jar;D:softmavenstoragecommons-fileuploadcommons-fileupload1.3.3commons-fileupload-1.3.3.jar;D:softmavenstoragecommons-iocommons-io2.6commons-io-2.6.jar;D:softmavenstorageorgspringframeworkspring-web5.0.10.RELEASEspring-web-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkspring-beans5.0.10.RELEASEspring-beans-5.0.10.RELEASE.jar;D:softmavenstorageorgspringframeworkcloudspring-cloud-commons2.0.2.RELEASEspring-cloud-commons-2.0.2.RELEASE.jar;D:softmavenstorageorgspringframeworksecurityspring-security-crypto5.0.9.RELEASEspring-security-crypto-5.0.9.RELEASE.jar;D:softmavenstorageiogithubopenfeignfeign-core9.7.0feign-core-9.7.0.jar;D:softmavenstorageiogithubopenfeignfeign-slf4j9.7.0feign-slf4j-9.7.0.jar;D:softmavenstorageiogithubopenfeignfeign-hystrix9.7.0feign-hystrix-9.7.0.jar;D:softmavenstoragecomnetflixhystrixhystrix-core1.5.12hystrix-core-1.5.12.jar;D:softmavenstorageiogithubopenfeignfeign-java89.7.0feign-java8-9.7.0.jar;D:softmavenstorageorgapachecommonscommons-lang33.9commons-lang3-3.9.jar;D:softmavenstorageorgopenjdkjmhjmh-core1.23jmh-core-1.23.jar;D:softmavenstoragenetsfjopt-simplejopt-simple5.0.4jopt-simple-5.0.4.jar;D:softmavenstorageorgapachecommonscommons-math33.2commons-math3-3.2.jar;D:softmavenstorageorgopenjdkjmhjmh-generator-annprocess1.23jmh-generator-annprocess-1.23.jar" StringBuilderTest
*/
# JMH version: 1.23
# VM version: JDK 1.8.0_172, Java HotSpot(TM) 64-Bit Server VM, 25.172-b11
# VM invoker: C:Program FilesJavajdk1.8.0_172jrebinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 10 s each
# Measurement: 3 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: other.StringConnectBenchmark.testStringAdd
# Run progress: 0.00% complete, ETA 00:15:00
# Fork: 1 of 3
# Warmup Iteration 1: 64581139.881 ops/s
# Warmup Iteration 2: 54027413.844 ops/s
# Warmup Iteration 3: 27501597.300 ops/s
Iteration 1: 27797251.911 ops/s
Iteration 2: 27784612.013 ops/s
Iteration 3: 27537456.085 ops/s
# Run progress: 6.67% complete, ETA 00:14:19
# Fork: 2 of 3
# Warmup Iteration 1: 63807104.679 ops/s
# Warmup Iteration 2: 26975853.480 ops/s
# Warmup Iteration 3: 27483412.622 ops/s
Iteration 1: 26629769.930 ops/s
Iteration 2: 24785483.310 ops/s
Iteration 3: 25814545.283 ops/s
# Run progress: 13.33% complete, ETA 00:13:17
# Fork: 3 of 3
# Warmup Iteration 1: 58088834.066 ops/s
# Warmup Iteration 2: 26381444.844 ops/s
# Warmup Iteration 3: 26551271.489 ops/s
Iteration 1: 27455830.966 ops/s
Iteration 2: 25024428.092 ops/s
Iteration 3: 26768626.386 ops/s
Result "other.StringConnectBenchmark.testStringAdd":
26622000.442 ±(99.9%) 1958337.006 ops/s [Average]
(min, avg, max) = (24785483.310, 26622000.442, 27797251.911), stdev = 1165374.940
CI (99.9%): [24663663.435, 28580337.448] (assumes normal distribution)
# JMH version: 1.23
# VM version: JDK 1.8.0_172, Java HotSpot(TM) 64-Bit Server VM, 25.172-b11
# VM invoker: C:Program FilesJavajdk1.8.0_172jrebinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 10 s each
# Measurement: 3 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: other.StringConnectBenchmark.testStringBuffer
# Run progress: 20.00% complete, ETA 00:12:15
# Fork: 1 of 3
# Warmup Iteration 1: 94419276.198 ops/s
# Warmup Iteration 2: 95971690.238 ops/s
# Warmup Iteration 3: 100676200.521 ops/s
Iteration 1: 98424308.605 ops/s
Iteration 2: 96882301.733 ops/s
Iteration 3: 94511362.279 ops/s
# Run progress: 26.67% complete, ETA 00:11:14
# Fork: 2 of 3
# Warmup Iteration 1: 88074293.697 ops/s
# Warmup Iteration 2: 93004432.469 ops/s
# Warmup Iteration 3: 101579019.397 ops/s
Iteration 1: 103726491.983 ops/s
Iteration 2: 99056528.514 ops/s
Iteration 3: 100929905.391 ops/s
# Run progress: 33.33% complete, ETA 00:10:12
# Fork: 3 of 3
# Warmup Iteration 1: 84038667.008 ops/s
# Warmup Iteration 2: 90818017.799 ops/s
# Warmup Iteration 3: 100763178.367 ops/s
Iteration 1: 100324219.382 ops/s
Iteration 2: 99833188.220 ops/s
Iteration 3: 92450357.608 ops/s
Result "other.StringConnectBenchmark.testStringBuffer":
98459851.524 ±(99.9%) 5752610.940 ops/s [Average]
(min, avg, max) = (92450357.608, 98459851.524, 103726491.983), stdev = 3423286.497
CI (99.9%): [92707240.584, 104212462.464] (assumes normal distribution)
# JMH version: 1.23
# VM version: JDK 1.8.0_172, Java HotSpot(TM) 64-Bit Server VM, 25.172-b11
# VM invoker: C:Program FilesJavajdk1.8.0_172jrebinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 10 s each
# Measurement: 3 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: other.StringConnectBenchmark.testStringBuilder
# Run progress: 40.00% complete, ETA 00:09:11
# Fork: 1 of 3
# Warmup Iteration 1: 82773322.182 ops/s
# Warmup Iteration 2: 80655844.151 ops/s
# Warmup Iteration 3: 96470218.242 ops/s
Iteration 1: 90395211.886 ops/s
Iteration 2: 101943732.502 ops/s
Iteration 3: 103799901.400 ops/s
# Run progress: 46.67% complete, ETA 00:08:10
# Fork: 2 of 3
# Warmup Iteration 1: 83931190.691 ops/s
# Warmup Iteration 2: 92533541.878 ops/s
# Warmup Iteration 3: 99077059.697 ops/s
Iteration 1: 103059988.591 ops/s
Iteration 2: 98902244.458 ops/s
Iteration 3: 101523680.832 ops/s
# Run progress: 53.33% complete, ETA 00:07:08
# Fork: 3 of 3
# Warmup Iteration 1: 93036654.990 ops/s
# Warmup Iteration 2: 96964466.705 ops/s
# Warmup Iteration 3: 104358908.950 ops/s
Iteration 1: 104168902.450 ops/s
Iteration 2: 104526989.786 ops/s
Iteration 3: 104236397.319 ops/s
Result "other.StringConnectBenchmark.testStringBuilder":
101395227.691 ±(99.9%) 7554018.727 ops/s [Average]
(min, avg, max) = (90395211.886, 101395227.691, 104526989.786), stdev = 4495275.377
CI (99.9%): [93841208.964, 108949246.419] (assumes normal distribution)
# JMH version: 1.23
# VM version: JDK 1.8.0_172, Java HotSpot(TM) 64-Bit Server VM, 25.172-b11
# VM invoker: C:Program FilesJavajdk1.8.0_172jrebinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 10 s each
# Measurement: 3 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: other.StringConnectBenchmark.testStringConcat
# Run progress: 60.00% complete, ETA 00:06:07
# Fork: 1 of 3
# Warmup Iteration 1: 37535985.371 ops/s
# Warmup Iteration 2: 38545597.944 ops/s
# Warmup Iteration 3: 39049663.456 ops/s
Iteration 1: 37801324.814 ops/s
Iteration 2: 37335710.065 ops/s
Iteration 3: 38264331.857 ops/s
# Run progress: 66.67% complete, ETA 00:05:06
# Fork: 2 of 3
# Warmup Iteration 1: 33661805.217 ops/s
# Warmup Iteration 2: 37872149.542 ops/s
# Warmup Iteration 3: 35447811.830 ops/s
Iteration 1: 36062969.071 ops/s
Iteration 2: 38341045.482 ops/s
Iteration 3: 37409996.016 ops/s
# Run progress: 73.33% complete, ETA 00:04:05
# Fork: 3 of 3
# Warmup Iteration 1: 36747466.239 ops/s
# Warmup Iteration 2: 38103004.746 ops/s
# Warmup Iteration 3: 35424223.595 ops/s
Iteration 1: 35196912.629 ops/s
Iteration 2: 39585691.903 ops/s
Iteration 3: 36581347.705 ops/s
Result "other.StringConnectBenchmark.testStringConcat":
37397703.283 ±(99.9%) 2213982.849 ops/s [Average]
(min, avg, max) = (35196912.629, 37397703.283, 39585691.903), stdev = 1317505.681
CI (99.9%): [35183720.434, 39611686.131] (assumes normal distribution)
# JMH version: 1.23
# VM version: JDK 1.8.0_172, Java HotSpot(TM) 64-Bit Server VM, 25.172-b11
# VM invoker: C:Program FilesJavajdk1.8.0_172jrebinjava.exe
# VM options: -javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7libidea_rt.jar=55689:D:Program FilesJetBrainsIntelliJ IDEA 2017.3.7bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 10 s each
# Measurement: 3 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: other.StringConnectBenchmark.testStringFormat
# Run progress: 80.00% complete, ETA 00:03:03
# Fork: 1 of 3
# Warmup Iteration 1: 929281.585 ops/s
# Warmup Iteration 2: 942560.829 ops/s
# Warmup Iteration 3: 930529.780 ops/s
Iteration 1: 928678.666 ops/s
Iteration 2: 944020.601 ops/s
Iteration 3: 939737.773 ops/s
# Run progress: 86.67% complete, ETA 00:02:02
# Fork: 2 of 3
# Warmup Iteration 1: 885630.694 ops/s
# Warmup Iteration 2: 920004.820 ops/s
# Warmup Iteration 3: 908068.347 ops/s
Iteration 1: 917794.756 ops/s
Iteration 2: 915539.989 ops/s
Iteration 3: 910992.051 ops/s
# Run progress: 93.33% complete, ETA 00:01:01
# Fork: 3 of 3
# Warmup Iteration 1: 906535.933 ops/s
# Warmup Iteration 2: 924492.648 ops/s
# Warmup Iteration 3: 910368.898 ops/s
Iteration 1: 913355.243 ops/s
Iteration 2: 863162.026 ops/s
Iteration 3: 923308.505 ops/s
Result "other.StringConnectBenchmark.testStringFormat":
917398.846 ±(99.9%) 39286.558 ops/s [Average]
(min, avg, max) = (863162.026, 917398.846, 944020.601), stdev = 23378.800
CI (99.9%): [878112.288, 956685.403] (assumes normal distribution)
# Run complete. Total time: 00:15:18
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
StringConnectBenchmark.testStringAdd thrpt 9 26622000.442 ± 1958337.006 ops/s
StringConnectBenchmark.testStringBuffer thrpt 9 98459851.524 ± 5752610.940 ops/s
StringConnectBenchmark.testStringBuilder thrpt 9 101395227.691 ± 7554018.727 ops/s
StringConnectBenchmark.testStringConcat thrpt 9 37397703.283 ± 2213982.849 ops/s
StringConnectBenchmark.testStringFormat thrpt 9 917398.846 ± 39286.558 ops/s
Process finished with exit code 0
前面的都是一些输出的过程, 最重要的是最后的一些信息, . 它表示了, 吞吐率, 因为执行这个String 的相加的时间很短, 所以我们这里测试选择的是吞吐率, 然后执行比较长的耗时操作, 可以选择查看时间.
其实这个做一个评测时候非常的有用, 必须你要比较ArrayList 和 LinkedList 在一些增加元素, 删除元素, 之类的性能比较的时候, 用这个非常的好.比自己用System.currentTimeMillis() 会准确很好.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/157658.html原文链接:https://javaforall.cn