大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
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就不需要了, 已经包含在里面了.
</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 有两种方式, 一种是注解, 一种是代码配置的方式,
这里我们就说代码配置的方式, 因为这个东西用的不多, 记不住那么多的注解.
上代码:
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);
}
}
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 |
这里你们就知道了, 其实写配置 和 写注解是一样的, 没啥大的区别.
下面是运行结果:
"C:\Program Files\Java\jdk1.8.0_172\bin\java" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_172\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\rt.jar;D:\workspace\2020\goods\target\classes;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-netflix-eureka-client\2.0.2.RELEASE\spring-cloud-starter-netflix-eureka-client-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter\2.0.2.RELEASE\spring-cloud-starter-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-context\2.0.2.RELEASE\spring-cloud-context-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;D:\soft\mavenstorage\org\bouncycastle\bcpkix-jdk15on\1.59\bcpkix-jdk15on-1.59.jar;D:\soft\mavenstorage\org\bouncycastle\bcprov-jdk15on\1.59\bcprov-jdk15on-1.59.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-netflix-core\2.0.2.RELEASE\spring-cloud-netflix-core-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-autoconfigure\2.0.6.RELEASE\spring-boot-autoconfigure-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.0.2.RELEASE\spring-cloud-netflix-eureka-client-2.0.2.RELEASE.jar;D:\soft\mavenstorage\com\netflix\eureka\eureka-client\1.9.3\eureka-client-1.9.3.jar;D:\soft\mavenstorage\org\codehaus\jettison\jettison\1.2\jettison-1.2.jar;D:\soft\mavenstorage\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\soft\mavenstorage\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\soft\mavenstorage\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;D:\soft\mavenstorage\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;D:\soft\mavenstorage\joda-time\joda-time\2.9.9\joda-time-2.9.9.jar;D:\soft\mavenstorage\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;D:\soft\mavenstorage\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;D:\soft\mavenstorage\antlr\antlr\2.7.7\antlr-2.7.7.jar;D:\soft\mavenstorage\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;D:\soft\mavenstorage\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;D:\soft\mavenstorage\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\soft\mavenstorage\com\google\guava\guava\20.0\guava-20.0.jar;D:\soft\mavenstorage\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\soft\mavenstorage\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\soft\mavenstorage\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\soft\mavenstorage\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\soft\mavenstorage\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\soft\mavenstorage\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;D:\soft\mavenstorage\org\apache\httpcomponents\httpcore\4.4.10\httpcore-4.4.10.jar;D:\soft\mavenstorage\com\google\inject\guice\3.0\guice-3.0.jar;D:\soft\mavenstorage\javax\inject\javax.inject\1\javax.inject-1.jar;D:\soft\mavenstorage\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\soft\mavenstorage\com\github\vlsi\compactmap\compactmap\1.2.1\compactmap-1.2.1.jar;D:\soft\mavenstorage\com\github\andrewoma\dexx\dexx-collections\0.2\dexx-collections-0.2.jar;D:\soft\mavenstorage\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\soft\mavenstorage\com\fasterxml\jackson\core\jackson-core\2.9.7\jackson-core-2.9.7.jar;D:\soft\mavenstorage\com\fasterxml\jackson\core\jackson-databind\2.9.7\jackson-databind-2.9.7.jar;D:\soft\mavenstorage\com\netflix\eureka\eureka-core\1.9.3\eureka-core-1.9.3.jar;D:\soft\mavenstorage\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;D:\soft\mavenstorage\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;D:\soft\mavenstorage\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.0.2.RELEASE\spring-cloud-starter-netflix-archaius-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-netflix-ribbon\2.0.2.RELEASE\spring-cloud-netflix-ribbon-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-netflix-archaius\2.0.2.RELEASE\spring-cloud-netflix-archaius-2.0.2.RELEASE.jar;D:\soft\mavenstorage\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\soft\mavenstorage\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.0.2.RELEASE\spring-cloud-starter-netflix-ribbon-2.0.2.RELEASE.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon\2.2.5\ribbon-2.2.5.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon-transport\2.2.5\ribbon-transport-2.2.5.jar;D:\soft\mavenstorage\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\soft\mavenstorage\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\soft\mavenstorage\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon-core\2.2.5\ribbon-core-2.2.5.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon-httpclient\2.2.5\ribbon-httpclient-2.2.5.jar;D:\soft\mavenstorage\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\soft\mavenstorage\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon-loadbalancer\2.2.5\ribbon-loadbalancer-2.2.5.jar;D:\soft\mavenstorage\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\soft\mavenstorage\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\soft\mavenstorage\com\netflix\ribbon\ribbon-eureka\2.2.5\ribbon-eureka-2.2.5.jar;D:\soft\mavenstorage\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\soft\mavenstorage\com\thoughtworks\xstream\xstream\1.4.10\xstream-1.4.10.jar;D:\soft\mavenstorage\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\soft\mavenstorage\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\soft\mavenstorage\com\alibaba\cloud\spring-cloud-starter-alibaba-sentinel\2.0.0.RELEASE\spring-cloud-starter-alibaba-sentinel-2.0.0.RELEASE.jar;D:\soft\mavenstorage\com\alibaba\cloud\spring-cloud-alibaba-sentinel\2.0.0.RELEASE\spring-cloud-alibaba-sentinel-2.0.0.RELEASE.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-annotation-aspectj\1.6.3\sentinel-annotation-aspectj-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-core\1.6.3\sentinel-core-1.6.3.jar;D:\soft\mavenstorage\org\aspectj\aspectjrt\1.8.13\aspectjrt-1.8.13.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-web-servlet\1.6.3\sentinel-web-servlet-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-spring-webflux-adapter\1.6.3\sentinel-spring-webflux-adapter-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-reactor-adapter\1.6.3\sentinel-reactor-adapter-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-parameter-flow-control\1.6.3\sentinel-parameter-flow-control-1.6.3.jar;D:\soft\mavenstorage\com\googlecode\concurrentlinkedhashmap\concurrentlinkedhashmap-lru\1.4.2\concurrentlinkedhashmap-lru-1.4.2.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-cluster-server-default\1.6.3\sentinel-cluster-server-default-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-cluster-common-default\1.6.3\sentinel-cluster-common-default-1.6.3.jar;D:\soft\mavenstorage\io\netty\netty-handler\4.1.29.Final\netty-handler-4.1.29.Final.jar;D:\soft\mavenstorage\io\netty\netty-buffer\4.1.29.Final\netty-buffer-4.1.29.Final.jar;D:\soft\mavenstorage\io\netty\netty-common\4.1.29.Final\netty-common-4.1.29.Final.jar;D:\soft\mavenstorage\io\netty\netty-transport\4.1.29.Final\netty-transport-4.1.29.Final.jar;D:\soft\mavenstorage\io\netty\netty-resolver\4.1.29.Final\netty-resolver-4.1.29.Final.jar;D:\soft\mavenstorage\io\netty\netty-codec\4.1.29.Final\netty-codec-4.1.29.Final.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-cluster-client-default\1.6.3\sentinel-cluster-client-default-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\cloud\spring-cloud-alibaba-sentinel-datasource\2.0.0.RELEASE\spring-cloud-alibaba-sentinel-datasource-2.0.0.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter\2.0.6.RELEASE\spring-boot-starter-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot\2.0.6.RELEASE\spring-boot-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-logging\2.0.6.RELEASE\spring-boot-starter-logging-2.0.6.RELEASE.jar;D:\soft\mavenstorage\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\soft\mavenstorage\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\soft\mavenstorage\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;D:\soft\mavenstorage\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;D:\soft\mavenstorage\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\soft\mavenstorage\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\soft\mavenstorage\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;D:\soft\mavenstorage\org\springframework\spring-core\5.0.10.RELEASE\spring-core-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-jcl\5.0.10.RELEASE\spring-jcl-5.0.10.RELEASE.jar;D:\soft\mavenstorage\com\curefun\application\application-pom\1.0.0\application-pom-1.0.0.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-zipkin\2.0.2.RELEASE\spring-cloud-starter-zipkin-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-sleuth\2.0.2.RELEASE\spring-cloud-starter-sleuth-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-sleuth-core\2.0.2.RELEASE\spring-cloud-sleuth-core-2.0.2.RELEASE.jar;D:\soft\mavenstorage\io\zipkin\brave\brave\5.4.3\brave-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-context-log4j2\5.4.3\brave-context-log4j2-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-spring-web\5.4.3\brave-instrumentation-spring-web-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-http\5.4.3\brave-instrumentation-http-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-spring-rabbit\5.4.3\brave-instrumentation-spring-rabbit-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-kafka-clients\5.4.3\brave-instrumentation-kafka-clients-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-httpclient\5.4.3\brave-instrumentation-httpclient-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-httpasyncclient\5.4.3\brave-instrumentation-httpasyncclient-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-spring-webmvc\5.4.3\brave-instrumentation-spring-webmvc-5.4.3.jar;D:\soft\mavenstorage\io\zipkin\brave\brave-instrumentation-servlet\5.4.3\brave-instrumentation-servlet-5.4.3.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-sleuth-zipkin\2.0.2.RELEASE\spring-cloud-sleuth-zipkin-2.0.2.RELEASE.jar;D:\soft\mavenstorage\io\zipkin\zipkin2\zipkin\2.11.7\zipkin-2.11.7.jar;D:\soft\mavenstorage\io\zipkin\reporter2\zipkin-reporter\2.7.10\zipkin-reporter-2.7.10.jar;D:\soft\mavenstorage\io\zipkin\reporter2\zipkin-sender-kafka11\2.7.10\zipkin-sender-kafka11-2.7.10.jar;D:\soft\mavenstorage\io\zipkin\reporter2\zipkin-sender-amqp-client\2.7.10\zipkin-sender-amqp-client-2.7.10.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-transport-simple-http\1.6.3\sentinel-transport-simple-http-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-transport-common\1.6.3\sentinel-transport-common-1.6.3.jar;D:\soft\mavenstorage\com\alibaba\csp\sentinel-datasource-extension\1.6.3\sentinel-datasource-extension-1.6.3.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-actuator\2.0.6.RELEASE\spring-boot-starter-actuator-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-actuator-autoconfigure\2.0.6.RELEASE\spring-boot-actuator-autoconfigure-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-actuator\2.0.6.RELEASE\spring-boot-actuator-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-context\5.0.10.RELEASE\spring-context-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-expression\5.0.10.RELEASE\spring-expression-5.0.10.RELEASE.jar;D:\soft\mavenstorage\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.7\jackson-datatype-jsr310-2.9.7.jar;D:\soft\mavenstorage\io\micrometer\micrometer-core\1.0.7\micrometer-core-1.0.7.jar;D:\soft\mavenstorage\org\hdrhistogram\HdrHistogram\2.1.10\HdrHistogram-2.1.10.jar;D:\soft\mavenstorage\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;D:\soft\mavenstorage\com\curefun\core\curefun-core\1.0.46\curefun-core-1.0.46.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-web\2.0.6.RELEASE\spring-boot-starter-web-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-json\2.0.6.RELEASE\spring-boot-starter-json-2.0.6.RELEASE.jar;D:\soft\mavenstorage\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.7\jackson-datatype-jdk8-2.9.7.jar;D:\soft\mavenstorage\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.7\jackson-module-parameter-names-2.9.7.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-tomcat\2.0.6.RELEASE\spring-boot-starter-tomcat-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\apache\tomcat\embed\tomcat-embed-core\8.5.34\tomcat-embed-core-8.5.34.jar;D:\soft\mavenstorage\org\apache\tomcat\embed\tomcat-embed-el\8.5.34\tomcat-embed-el-8.5.34.jar;D:\soft\mavenstorage\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.34\tomcat-embed-websocket-8.5.34.jar;D:\soft\mavenstorage\org\hibernate\validator\hibernate-validator\6.0.13.Final\hibernate-validator-6.0.13.Final.jar;D:\soft\mavenstorage\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\soft\mavenstorage\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\soft\mavenstorage\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;D:\soft\mavenstorage\org\springframework\spring-webmvc\5.0.10.RELEASE\spring-webmvc-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-aop\2.0.6.RELEASE\spring-boot-starter-aop-2.0.6.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-aop\5.0.10.RELEASE\spring-aop-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\aspectj\aspectjweaver\1.8.13\aspectjweaver-1.8.13.jar;D:\soft\mavenstorage\com\baomidou\mybatis-plus-boot-starter\3.0.7\mybatis-plus-boot-starter-3.0.7.jar;D:\soft\mavenstorage\com\baomidou\mybatis-plus\3.0.7\mybatis-plus-3.0.7.jar;D:\soft\mavenstorage\com\baomidou\mybatis-plus-extension\3.0.7\mybatis-plus-extension-3.0.7.jar;D:\soft\mavenstorage\com\baomidou\mybatis-plus-core\3.0.7\mybatis-plus-core-3.0.7.jar;D:\soft\mavenstorage\com\baomidou\mybatis-plus-annotation\3.0.7\mybatis-plus-annotation-3.0.7.jar;D:\soft\mavenstorage\com\github\jsqlparser\jsqlparser\1.3\jsqlparser-1.3.jar;D:\soft\mavenstorage\org\mybatis\mybatis-spring\1.3.2\mybatis-spring-1.3.2.jar;D:\soft\mavenstorage\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;D:\soft\mavenstorage\org\springframework\boot\spring-boot-starter-jdbc\2.0.6.RELEASE\spring-boot-starter-jdbc-2.0.6.RELEASE.jar;D:\soft\mavenstorage\com\zaxxer\HikariCP\2.7.9\HikariCP-2.7.9.jar;D:\soft\mavenstorage\org\springframework\spring-jdbc\5.0.10.RELEASE\spring-jdbc-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-tx\5.0.10.RELEASE\spring-tx-5.0.10.RELEASE.jar;D:\soft\mavenstorage\com\alibaba\druid-spring-boot-starter\1.1.10\druid-spring-boot-starter-1.1.10.jar;D:\soft\mavenstorage\com\alibaba\druid\1.1.10\druid-1.1.10.jar;D:\soft\mavenstorage\org\projectlombok\lombok\1.16.22\lombok-1.16.22.jar;D:\soft\mavenstorage\com\alibaba\fastjson\1.2.47\fastjson-1.2.47.jar;D:\soft\mavenstorage\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar;D:\soft\mavenstorage\com\squareup\okhttp3\okhttp\3.8.1\okhttp-3.8.1.jar;D:\soft\mavenstorage\com\squareup\okio\okio\1.13.0\okio-1.13.0.jar;D:\soft\mavenstorage\com\google\zxing\core\3.2.1\core-3.2.1.jar;D:\soft\mavenstorage\com\google\zxing\javase\3.2.1\javase-3.2.1.jar;D:\soft\mavenstorage\com\beust\jcommander\1.48\jcommander-1.48.jar;D:\soft\mavenstorage\ar\com\hjg\pngj\2.1.0\pngj-2.1.0.jar;D:\soft\mavenstorage\org\apache\poi\poi\3.14\poi-3.14.jar;D:\soft\mavenstorage\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\soft\mavenstorage\org\apache\poi\poi-ooxml\3.14\poi-ooxml-3.14.jar;D:\soft\mavenstorage\org\apache\poi\poi-ooxml-schemas\3.14\poi-ooxml-schemas-3.14.jar;D:\soft\mavenstorage\org\apache\xmlbeans\xmlbeans\2.6.0\xmlbeans-2.6.0.jar;D:\soft\mavenstorage\com\github\virtuald\curvesapi\1.03\curvesapi-1.03.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-starter-openfeign\2.0.2.RELEASE\spring-cloud-starter-openfeign-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-openfeign-core\2.0.2.RELEASE\spring-cloud-openfeign-core-2.0.2.RELEASE.jar;D:\soft\mavenstorage\io\github\openfeign\form\feign-form-spring\3.3.0\feign-form-spring-3.3.0.jar;D:\soft\mavenstorage\io\github\openfeign\form\feign-form\3.3.0\feign-form-3.3.0.jar;D:\soft\mavenstorage\com\google\code\findbugs\annotations\3.0.1\annotations-3.0.1.jar;D:\soft\mavenstorage\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar;D:\soft\mavenstorage\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;D:\soft\mavenstorage\commons-fileupload\commons-fileupload\1.3.3\commons-fileupload-1.3.3.jar;D:\soft\mavenstorage\commons-io\commons-io\2.6\commons-io-2.6.jar;D:\soft\mavenstorage\org\springframework\spring-web\5.0.10.RELEASE\spring-web-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\spring-beans\5.0.10.RELEASE\spring-beans-5.0.10.RELEASE.jar;D:\soft\mavenstorage\org\springframework\cloud\spring-cloud-commons\2.0.2.RELEASE\spring-cloud-commons-2.0.2.RELEASE.jar;D:\soft\mavenstorage\org\springframework\security\spring-security-crypto\5.0.9.RELEASE\spring-security-crypto-5.0.9.RELEASE.jar;D:\soft\mavenstorage\io\github\openfeign\feign-core\9.7.0\feign-core-9.7.0.jar;D:\soft\mavenstorage\io\github\openfeign\feign-slf4j\9.7.0\feign-slf4j-9.7.0.jar;D:\soft\mavenstorage\io\github\openfeign\feign-hystrix\9.7.0\feign-hystrix-9.7.0.jar;D:\soft\mavenstorage\com\netflix\hystrix\hystrix-core\1.5.12\hystrix-core-1.5.12.jar;D:\soft\mavenstorage\io\github\openfeign\feign-java8\9.7.0\feign-java8-9.7.0.jar;D:\soft\mavenstorage\org\apache\commons\commons-lang3\3.9\commons-lang3-3.9.jar;D:\soft\mavenstorage\org\openjdk\jmh\jmh-core\1.23\jmh-core-1.23.jar;D:\soft\mavenstorage\net\sf\jopt-simple\jopt-simple\5.0.4\jopt-simple-5.0.4.jar;D:\soft\mavenstorage\org\apache\commons\commons-math3\3.2\commons-math3-3.2.jar;D:\soft\mavenstorage\org\openjdk\jmh\jmh-generator-annprocess\1.23\jmh-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 Files\Java\jdk1.8.0_172\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -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 Files\Java\jdk1.8.0_172\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -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 Files\Java\jdk1.8.0_172\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -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 Files\Java\jdk1.8.0_172\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -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 Files\Java\jdk1.8.0_172\jre\bin\java.exe
# VM options: -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\lib\idea_rt.jar=55689:D:\Program Files\JetBrains\IntelliJ IDEA 2017.3.7\bin -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() 会准确很好.
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/157658.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...