對於 Java 開發者來講,要去學習性能測試工具未免很麻煩。java
但有時候會有性能測試的需求。git
junitperf 就是一款爲 Java 開發者設計的性能測試框架,若是你會 Junit,很容易就能夠學會。github
入門案例地址框架
<dependency> <groupId>com.github.houbb</groupId> <artifactId>junitperf</artifactId> <version>2.0.0</version> </dependency>
import com.github.houbb.junitperf.core.annotation.JunitPerfConfig; public class HelloWorldTest { @JunitPerfConfig(duration = 1000) public void helloTest() throws InterruptedException { Thread.sleep(100); System.out.println("Hello Junit5"); } }
[INFO] 2018-01-14 22:16:31.419 [] - Started at: 2018-01-14 22:16:30.194 [INFO] 2018-01-14 22:16:31.419 [] - Invocations: 10 [INFO] 2018-01-14 22:16:31.420 [] - Success: 10 [INFO] 2018-01-14 22:16:31.420 [] - Errors: 0 [INFO] 2018-01-14 22:16:31.420 [] - Thread Count: 2 [INFO] 2018-01-14 22:16:31.421 [] - Warm up: 0ms [INFO] 2018-01-14 22:16:31.421 [] - Execution time: 1000ms [INFO] 2018-01-14 22:16:31.421 [] - Throughput: 10/s (Required: -1/s) - PASSED [INFO] 2018-01-14 22:16:31.424 [] - Min latency: 200.2112ms (Required: -1.0ms) - PASSED [INFO] 2018-01-14 22:16:31.424 [] - Max latency: 205.67862ms (Required: -1.0ms) - PASSED [INFO] 2018-01-14 22:16:31.425 [] - Ave latency: 202.97829ms (Required: -1.0ms) - PASSED